--- l2_test.c 2001/11/07 11:37:18 1.42
+++ l2_test.c 2001/11/07 13:05:20 1.43
@@ -31,14 +31,16 @@
#include "l2.h"
-static void die(char *fmt, ...)
+static void die(l2_env_t *env, l2_result_t rv, char *fmt, ...)
{
va_list ap;
+ char *error;
va_start(ap, fmt);
fprintf(stderr, "l2_test:ERROR: ");
vfprintf(stderr, fmt, ap);
- fprintf(stderr, "\n");
+ error = l2_env_strerror(env, rv);
+ fprintf(stderr, " (%s)\n", error);
va_end(ap);
exit(1);
}
@@ -64,87 +66,86 @@
l2_channel_t *chFile;
l2_channel_t *chSyslog;
l2_channel_t *chSmtp;
+ l2_result_t rv;
l2_env_t *env;
/* create environment */
- if ((l2_env_create(&env)) != L2_OK)
- die("failed to create environment");
- if (l2_env_formatter(env, 'k', formatter, NULL) != L2_OK)
- die("failed to configure formatter for %%x");
- if (l2_env_formatter(env, 'S', l2_util_fmt_dump, NULL) != L2_OK)
- die("failed to configure formatter for %%S");
+ if ((rv = l2_env_create(&env)) != L2_OK)
+ die(env, rv, "failed to create environment");
+ if ((rv = l2_env_formatter(env, 'k', formatter, NULL)) != L2_OK)
+ die(env, rv, "failed to configure formatter for %%x");
+ if ((rv = l2_env_formatter(env, 'S', l2_util_fmt_dump, NULL)) != L2_OK)
+ die(env, rv, "failed to configure formatter for %%S");
/* create noop channel */
- if ((l2_channel_create(&ch, env, "noop")) != L2_OK)
- die("failed to create noop channel");
+ if ((rv = l2_channel_create(&ch, env, "noop")) != L2_OK)
+ die(env, rv, "failed to create noop channel");
/* create prefix channel */
- if ((l2_channel_create(&chPrefix, env, "prefix")) != L2_OK)
- die("failed to create prefix channel");
- if (l2_channel_configure(chPrefix, "prefix,timezone",
- "[%d-%m-%Y/%H:%M:%S] %L test[%P]: ", "local") != L2_OK)
- die("failed to configure prefix channel");
+ if ((rv = l2_channel_create(&chPrefix, env, "prefix")) != L2_OK)
+ die(env, rv, "failed to create prefix channel");
+ if ((rv = l2_channel_configure(chPrefix, "prefix=\"%s\", timezone=local", "[%d-%m-%Y/%H:%M:%S] %L test[%P]: ")) != L2_OK)
+ die(env, rv, "failed to configure prefix channel");
/* create prefix channel */
- if ((l2_channel_create(&chFilter, env, "filter")) != L2_OK)
- die("failed to create filter channel");
- if (l2_channel_configure(chFilter, "regex,negate", "hecking", 0) != L2_OK)
- die("failed to configure filter channel");
+ if ((rv = l2_channel_create(&chFilter, env, "filter")) != L2_OK)
+ die(env, rv, "failed to create filter channel");
+ if ((rv = l2_channel_configure(chFilter, "regex=hecking, negate=0")) != L2_OK)
+ die(env, rv, "failed to configure filter channel");
/* create buffer channel */
- if ((l2_channel_create(&chBuffer, env, "buffer")) != L2_OK)
- die("failed to create buffer channel");
- if (l2_channel_configure(chBuffer, "size", 800) != L2_OK)
- die("failed to configure buffer channel");
+ if ((rv = l2_channel_create(&chBuffer, env, "buffer")) != L2_OK)
+ die(env, rv, "failed to create buffer channel");
+ if ((rv = l2_channel_configure(chBuffer, "size=800")) != L2_OK)
+ die(env, rv, "failed to configure buffer channel");
/* create file channel */
- if ((l2_channel_create(&chFile, env, "file")) != L2_OK)
- die("failed to create file channel");
- if (l2_channel_configure(chFile, "path,append,perm", "l2_test.log", TRUE, 0644) != L2_OK)
- die("failed to configure file channel");
- if (l2_channel_levels(chFile, L2_LEVEL_UPTO(L2_LEVEL_INFO), L2_LEVEL_NONE) != L2_OK)
- die("failed to level of smtp channel");
+ if ((rv = l2_channel_create(&chFile, env, "file")) != L2_OK)
+ die(env, rv, "failed to create file channel");
+ if ((rv = l2_channel_configure(chFile, "path=l2_test.log, append=%d,perm=%d", TRUE, 0644)) != L2_OK)
+ die(env, rv, "failed to configure file channel");
+ if ((rv = l2_channel_levels(chFile, L2_LEVEL_UPTO(L2_LEVEL_INFO), L2_LEVEL_NONE)) != L2_OK)
+ die(env, rv, "failed to level of smtp channel");
/* create syslog channel */
- if ((l2_channel_create(&chSyslog, env, "syslog")) != L2_OK)
- die("failed to create syslog channel");
- if (l2_channel_configure(chSyslog, "ident,facility,target,remotehost,logpid",
- "L2-Test", "user", "remote", "en1", 1) != L2_OK)
- die("failed to configure syslog channel");
- if (l2_channel_levels(chSyslog, L2_LEVEL_UPTO(L2_LEVEL_ERROR), L2_LEVEL_ALL) != L2_OK)
- die("failed to level of syslog channel");
+ if ((rv = l2_channel_create(&chSyslog, env, "syslog")) != L2_OK)
+ die(env, rv, "failed to create syslog channel");
+ if ((rv = l2_channel_configure(chSyslog, "ident=L2-Test, facility=user, target=remote, remotehost=en1, logpid=1")) != L2_OK)
+ die(env, rv, "failed to configure syslog channel");
+ if ((rv = l2_channel_levels(chSyslog, L2_LEVEL_UPTO(L2_LEVEL_ERROR), L2_LEVEL_ALL)) != L2_OK)
+ die(env, rv, "failed to level of syslog channel");
/* create smtp channel */
- if ((l2_channel_create(&chSmtp, env, "smtp")) != L2_OK)
- die("failed to create smtp channel");
- if (l2_channel_configure(chSmtp, "rcpt,host,port", "rse@engelschall.com", "en1", "25") != L2_OK)
- die("failed to configure smtp channel");
- if (l2_channel_levels(chSmtp, L2_LEVEL_UPTO(L2_LEVEL_PANIC), L2_LEVEL_ALL) != L2_OK)
- die("failed to level of smtp channel");
+ if ((rv = l2_channel_create(&chSmtp, env, "smtp")) != L2_OK)
+ die(env, rv, "failed to create smtp channel");
+ if ((rv = l2_channel_configure(chSmtp, "rcpt=rse@engelschall.com, host=en1, port=25")) != L2_OK)
+ die(env, rv, "failed to configure smtp channel");
+ if ((rv = l2_channel_levels(chSmtp, L2_LEVEL_UPTO(L2_LEVEL_PANIC), L2_LEVEL_ALL)) != L2_OK)
+ die(env, rv, "failed to level of smtp channel");
/* build channel tree */
- if (l2_channel_link(ch, L2_LINK_CHILD, chFilter, chPrefix, chBuffer, chFile, NULL) != L2_OK)
- die("failed to link file-related channels together as a child sequence");
- if (l2_channel_link(ch, L2_LINK_CHILD, chSyslog, NULL) != L2_OK)
- die("failed to link syslog-related channels together as a child sequence");
+ if ((rv = l2_channel_link(ch, L2_LINK_CHILD, chFilter, chPrefix, chBuffer, chFile, NULL)) != L2_OK)
+ die(env, rv, "failed to link file-related channels together as a child sequence");
+ if ((rv = l2_channel_link(ch, L2_LINK_CHILD, chSyslog, NULL)) != L2_OK)
+ die(env, rv, "failed to link syslog-related channels together as a child sequence");
/* open channel tree */
- if (l2_channel_open(ch) != L2_OK)
- die("failed to open channel tree");
+ if ((rv = l2_channel_open(ch)) != L2_OK)
+ die(env, rv, "failed to open channel tree");
/* perform a few log operations */
- if (l2_channel_log(ch, L2_LEVEL_PANIC, "1: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
- die("failed to log message #1 to channel");
- if (l2_channel_log(ch, L2_LEVEL_PANIC, "2: Shecking\n") != L2_OK)
- die("failed to log message #2 to channel");
- if (l2_channel_log(ch, L2_LEVEL_PANIC, "3: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7) != L2_OK)
- die("failed to log message #3 to channel");
- if (l2_channel_log(ch, L2_LEVEL_PANIC, "4: Shecking\n") != L2_OK)
- die("failed to log message #4 to channel");
+ if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "1: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7)) != L2_OK)
+ die(env, rv, "failed to log message #1 to channel");
+ if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "2: Shecking\n")) != L2_OK)
+ die(env, rv, "failed to log message #2 to channel");
+ if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "3: Checking localhost %s %{myparm}k <%{text}S><%{hex}S><%{base64}S>\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7)) != L2_OK)
+ die(env, rv, "failed to log message #3 to channel");
+ if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "4: Shecking\n")) != L2_OK)
+ die(env, rv, "failed to log message #4 to channel");
/* destroy channel tree */
- if (l2_channel_destroy(ch) != L2_OK)
- die("failed to destroy channel tree");
+ if ((rv = l2_channel_destroy(ch)) != L2_OK)
+ die(env, rv, "failed to destroy channel tree");
return 0;
}
|