head 1.56; access; symbols L2_0_9_13:1.56 FSL_1_7_0:1.56 L2_0_9_12:1.56 LMTP2NNTP_1_4_1:1.56 LMTP2NNTP_1_4_0:1.56 FSL_1_6_1:1.56 L2_0_9_11:1.56 FSL_1_6_0:1.55 FSL_1_6b2:1.55 L2_0_9_10:1.55 FSL_1_6b1:1.55 L2_0_9_9:1.55 LMTP2NNTP_1_3_0:1.54 LMTP2NNTP_1_3b2:1.54 LMTP2NNTP_1_3b1:1.54 LMTP2NNTP_1_3a3:1.54 FSL_1_5_0:1.54 LMTP2NNTP_1_3a2:1.54 FSL_1_5a3:1.54 LMTP2NNTP_1_3a1:1.54 FSL_1_5a2:1.54 L2_0_9_8:1.54 FSL_1_5a1:1.54 L2_0_9_7:1.54 L2_0_9_6:1.54 FSL_1_4_0:1.54 FSL_1_4b1:1.54 L2_0_9_5:1.54 FSL_1_4a1:1.54 FSL_1_3_0:1.54 FSL_1_3b1:1.54 L2_0_9_4:1.54 FSL_1_2_1:1.54 L2_0_9_3:1.54 FSL_1_2_0:1.54 L2_0_9_2:1.54 FSL_1_1_0:1.53 FSL_1_1b1:1.53 WORKOFF:1.53.0.2 WORKOFF_BP:1.53 FSL_1_0_8:1.53 LMTP2NNTP_1_2_0:1.53 LMTP2NNTP_1_2b4:1.53 LMTP2NNTP_1_2b3:1.53 LMTP2NNTP_1_2b2:1.53 LMTP2NNTP_1_2b1:1.52 LMTP2NNTP_1_2a8:1.52 LMTP2NNTP_1_2a7:1.52 FSL_1_0_7:1.52 FSL_1_0_6:1.50 FSL_1_0_5:1.50 FSL_1_0_4:1.50 L2_0_9_1:1.50 FSL_1_0_3:1.50 LMTP2NNTP_1_2a6:1.50 FSL_1_0_2:1.50 FSL_1_0_1:1.50 FSL_1_0_0:1.50 FSL_0_9_0:1.50 L2_0_9_0:1.50 FSL_0_1_12:1.49 FSL_0_1_11:1.49 FSL_0_1_10:1.49 FSL_0_1_9:1.49 FSL_0_1_8:1.49 FSL_0_1_7:1.49 FSL_0_1_6:1.49 FSL_0_1_5:1.49 FSL_0_1_1:1.49 LMTP2NNTP_1_2a5:1.49 LMTP2NNTP_1_2a4:1.49 LMTP2NNTP_1_2a3:1.49 LMTP2NNTP_1_2a1:1.48 LMTP2NNTP_1_1_1:1.33 LMTP2NNTP_1_1_0:1.33 LMTP2NNTP_1_1b4:1.33 LMTP2NNTP_1_1b3:1.33 L2_CHANNEL_ONLY_REVAMPING_BEFORE:1.36 LMTP2NNTP_1_1b2:1.33 LMTP2NNTP_1_1b1:1.33 L2_0_1_0:1.19 START_MICHAEL:1.4 L2_INITIAL:1.1.1.1 OSSP:1.1.1; locks; strict; comment @ * @; 1.56 date 2005.10.03.08.08.11; author rse; state Exp; branches; next 1.55; 1.55 date 2005.01.24.15.03.18; author rse; state Exp; branches; next 1.54; 1.54 date 2003.06.30.11.13.09; author thl; state Exp; branches; next 1.53; 1.53 date 2003.02.11.07.51.28; author rse; state Exp; branches; next 1.52; 1.52 date 2003.01.27.16.01.35; author thl; state Exp; branches; next 1.51; 1.51 date 2003.01.06.11.41.52; author rse; state Exp; branches; next 1.50; 1.50 date 2002.07.30.19.08.25; author rse; state Exp; branches; next 1.49; 1.49 date 2002.01.02.17.07.38; author rse; state Exp; branches; next 1.48; 1.48 date 2001.11.30.09.44.47; author rse; state Exp; branches; next 1.47; 1.47 date 2001.11.16.19.40.55; author ms; state Exp; branches; next 1.46; 1.46 date 2001.11.08.21.58.00; author rse; state Exp; branches; next 1.45; 1.45 date 2001.11.08.10.03.47; author rse; state Exp; branches; next 1.44; 1.44 date 2001.11.07.16.17.09; author rse; state Exp; branches; next 1.43; 1.43 date 2001.11.07.13.05.20; author rse; state Exp; branches; next 1.42; 1.42 date 2001.11.07.11.37.18; author rse; state Exp; branches; next 1.41; 1.41 date 2001.11.06.15.02.49; author rse; state Exp; branches; next 1.40; 1.40 date 2001.11.05.20.39.35; author rse; state Exp; branches; next 1.39; 1.39 date 2001.11.04.14.08.24; author rse; state Exp; branches; next 1.38; 1.38 date 2001.11.04.13.21.17; author rse; state Exp; branches; next 1.37; 1.37 date 2001.11.03.22.51.36; author rse; state Exp; branches; next 1.36; 1.36 date 2001.11.03.20.49.25; author rse; state Exp; branches; next 1.35; 1.35 date 2001.11.02.18.42.51; author ms; state Exp; branches; next 1.34; 1.34 date 2001.10.22.16.32.29; author ms; state Exp; branches; next 1.33; 1.33 date 2001.10.05.14.25.57; author ms; state Exp; branches; next 1.32; 1.32 date 2001.10.05.10.40.17; author ms; state Exp; branches; next 1.31; 1.31 date 2001.10.04.14.58.29; author ms; state Exp; branches; next 1.30; 1.30 date 2001.10.04.13.35.47; author ms; state Exp; branches; next 1.29; 1.29 date 2001.10.04.12.53.54; author ms; state Exp; branches; next 1.28; 1.28 date 2001.09.28.14.28.41; author ms; state Exp; branches; next 1.27; 1.27 date 2001.09.21.17.30.26; author ms; state Exp; branches; next 1.26; 1.26 date 2001.09.19.16.39.44; author ms; state Exp; branches; next 1.25; 1.25 date 2001.09.18.14.41.28; author ms; state Exp; branches; next 1.24; 1.24 date 2001.09.18.14.38.51; author ms; state Exp; branches; next 1.23; 1.23 date 2001.09.14.19.11.00; author rse; state Exp; branches; next 1.22; 1.22 date 2001.09.14.18.49.36; author rse; state Exp; branches; next 1.21; 1.21 date 2001.09.14.15.40.04; author ms; state Exp; branches; next 1.20; 1.20 date 2001.09.13.16.19.06; author ms; state Exp; branches; next 1.19; 1.19 date 2001.09.12.13.50.46; author rse; state Exp; branches; next 1.18; 1.18 date 2001.09.12.13.05.39; author rse; state Exp; branches; next 1.17; 1.17 date 2001.09.10.14.34.11; author ms; state Exp; branches; next 1.16; 1.16 date 2001.09.09.16.01.43; author rse; state Exp; branches; next 1.15; 1.15 date 2001.09.08.11.25.29; author rse; state Exp; branches; next 1.14; 1.14 date 2001.09.06.19.29.44; author ms; state Exp; branches; next 1.13; 1.13 date 2001.09.06.11.56.15; author rse; state Exp; branches; next 1.12; 1.12 date 2001.09.05.13.56.43; author rse; state Exp; branches; next 1.11; 1.11 date 2001.09.04.19.35.20; author ms; state Exp; branches; next 1.10; 1.10 date 2001.09.04.14.56.25; author rse; state Exp; branches; next 1.9; 1.9 date 2001.09.04.14.46.12; author rse; state Exp; branches; next 1.8; 1.8 date 2001.09.04.14.23.33; author ms; state Exp; branches; next 1.7; 1.7 date 2001.09.04.14.17.11; author ms; state Exp; branches; next 1.6; 1.6 date 2001.09.03.13.43.33; author rse; state Exp; branches; next 1.5; 1.5 date 2001.09.02.15.38.52; author ms; state Exp; branches; next 1.4; 1.4 date 2001.08.15.10.36.03; author rse; state Exp; branches; next 1.3; 1.3 date 2001.05.17.14.42.23; author simons; state Exp; branches; next 1.2; 1.2 date 2001.05.12.07.23.06; author rse; state Exp; branches; next 1.1; 1.1 date 2001.05.10.19.46.01; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.05.10.19.46.01; author rse; state Exp; branches; next ; desc @@ 1.56 log @Adjust copyright messages for new year 2005. @ text @/* ** OSSP l2 - Flexible Logging ** Copyright (c) 2001-2005 Cable & Wireless ** Copyright (c) 2001-2005 The OSSP Project ** Copyright (c) 2001-2005 Ralf S. Engelschall ** ** This file is part of OSSP l2, a flexible logging library which ** can be found at http://www.ossp.org/pkg/lib/l2/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** l2_test.c: C API test suite */ #include #include "l2.h" 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); error = l2_env_strerror(env, rv); fprintf(stderr, " (%s)\n", error); va_end(ap); exit(1); } static l2_result_t formatter(l2_context_t *ctx, const char id, const char *param, char *bufptr, size_t bufsize, size_t *buflen, va_list *ap) { int i; i = va_arg(*ap, int); sprintf(bufptr, "[%d/%s]", i, param); *buflen = strlen(bufptr); return L2_OK; } int main(int argc, char *argv[]) { l2_channel_t *ch; #if 1 char *spec; #else l2_channel_t *chFilter; l2_channel_t *chPrefix; l2_channel_t *chBuffer; l2_channel_t *chFile; l2_channel_t *chSyslog; l2_channel_t *chSmtp; #endif l2_result_t rv; l2_env_t *env; /* create environment */ 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"); if ((rv = l2_env_settimer(env, 20)) != L2_OK) die(env, rv, "failed to configure timer"); #if 1 spec = "noop -> {" " filter(regex=hecking, negate=0)" " -> prefix(prefix=\"[%d-%m-%Y/%H:%M:%S] %L test[%P]: \", timezone=local)" " -> buffer(size=800)" " -> file(path=l2_test.log, trunc=0, perm=0644) ;" /* " syslog(ident=L2-Test, facility=user, " " remotehost=localhost, logpid=1, target=remote)" */ "}"; fprintf(stderr, "configuring: %s\n", spec); if ((rv = l2_spec(&ch, env, "%s", spec)) != L2_OK) die(env, rv, "failed to parse specification"); #else /* 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 ((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 ((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 ((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 ((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, trunc=%d,perm=%d", 0, 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 ((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=localhost, 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 ((rv = l2_channel_create(&chSmtp, env, "smtp")) != L2_OK) die(env, rv, "failed to create smtp channel"); if ((rv = l2_channel_configure(chSmtp, "rcpt=l2@@localhost, host=localhost, 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 ((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"); #endif /* 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 ((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: Checking\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: Checking\n")) != L2_OK) die(env, rv, "failed to log message #4 to channel"); /* destroy channel tree */ if ((rv = l2_channel_destroy(ch)) != L2_OK) die(env, rv, "failed to destroy channel tree"); /* destroy environment */ if ((rv = l2_env_destroy(env)) != L2_OK) die(env, rv, "failed to destroy environment"); return 0; } @ 1.55 log @Adjust copyright messages for new year 2005. @ text @d3 3 a5 3 ** Copyright (c) 2001-2004 Cable & Wireless ** Copyright (c) 2001-2004 The OSSP Project ** Copyright (c) 2001-2004 Ralf S. Engelschall @ 1.54 log @introduce "trunc=" option for file channel; change default to append; keep support for obsolete "append" option @ text @d3 3 a5 3 ** Copyright (c) 2001-2003 Cable & Wireless Deutschland GmbH ** Copyright (c) 2001-2003 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2003 Ralf S. Engelschall @ 1.53 log @fix all dmalloc-detected memory leaks @ text @d92 1 a92 1 " -> file(path=l2_test.log, append=1, perm=0644) ;" d127 1 a127 1 if ((rv = l2_channel_configure(chFile, "path=l2_test.log, append=%d,perm=%d", TRUE, 0644)) != L2_OK) @ 1.52 log @fix iteration through non malloc(3)ed memory in l2_channel_destroy(). Bug caught on FreeBSD5 @ text @d173 4 @ 1.51 log @- remove trailing whitespaces - adjust copyright messages - consistently use "OSSP l2" - consistently talk about "Flexible Logging" - use standard OSSP ASCII-art @ text @a91 1 /* " -> buffer(size=800, timer=on)"*/ d93 1 d96 1 d162 1 a162 1 if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "2: Shecking\n")) != L2_OK) d166 1 a166 1 if ((rv = l2_channel_log(ch, L2_LEVEL_PANIC, "4: Shecking\n")) != L2_OK) @ 1.50 log @polish for release @ text @d2 4 a5 3 ** OSSP l2 - Logging Library ** Copyright (c) 2001-2002 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) d7 1 a7 1 ** This file is part of OSSP L2, a flexible logging library which d49 1 a49 1 static l2_result_t d54 1 a54 1 d157 1 a157 1 @ 1.49 log @bump copyright year @ text @d2 1 a2 1 ** L2 - OSSP Logging Library d7 1 a7 1 ** can be found at http://www.ossp.org/pkg/l2/. d92 1 a92 1 " -> file(path=l2_test.log, append=1, perm=420) ;" d94 1 a94 1 " remotehost=en1, logpid=1, target=remote)" d133 1 a133 1 if ((rv = l2_channel_configure(chSyslog, "ident=L2-Test, facility=user, target=remote, remotehost=en1, logpid=1")) != L2_OK) d141 1 a141 1 if ((rv = l2_channel_configure(chSmtp, "rcpt=rse@@engelschall.com, host=en1, port=25")) != L2_OK) @ 1.48 log @Allow a channel tree specification to be a printf-style string to make the API more powerful and to remove the burden from the application to pre-format the specification in an own buffer. @ text @d3 2 a4 2 ** Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.47 log @Mostly finished phase in of timer code to l2_env. Buffer needs work. @ text @d97 1 a97 1 if ((rv = l2_spec(&ch, env, spec)) != L2_OK) @ 1.46 log @Enhance the specification parser to be more smart in parsing parameter values in order to remove the burden on the user to provide massive syntactic sugar. One now can name=value or name="value" or even name=va"lu"e, i.e., do not require quotation marks. But if they are present they can be used to introduce spaces or special characters with \xXX notation. @ text @d83 2 d91 1 @ 1.45 log @fix old prefix problem, but find new one :-( @ text @d86 6 a91 6 " filter(regex=\"hecking\", negate=\"0\")" " -> prefix(prefix=\"[%d-%m-%Y/%H:%M:%S] %L test[%P]: \", timezone=\"local\")" " -> buffer(size=\"800\")" " -> file(path=\"l2_test.log\",append=\"1\",perm=\"420\") ;" " syslog(ident=\"L2-Test\", facility=\"user\", " " remotehost=\"en1\", logpid=\"1\", target=\"remote\")" @ 1.44 log @HEADS UP, guys: Here comes the first cut for the long-awaited channel tree specification parser and channel tree builder. This certainly makes L2 finally _THE_ killer library in the logging field. Woohooo... and the crowd goes wild! It allows one to build an arbitrary complex logging channel tree out of a single textual specification. An example follows: noop -> { prefix(prefix="[%d-%m-%Y/%H:%M:%S] %L test[%P]: ", timezone="local") -> filter(regex="hecking", negate="0") -> buffer(size="800") -> file(path="l2_test.log",append="1",perm="420"); error: syslog(ident="L2-Test", facility="user", remotehost="en1", logpid="1", target="remote"); panic: smtp(rcpt="rse@@engelschall.com", host="en1", port="25" } This allows one to log nice timestamp-prefixed messages containing the word "hecking" to a buffered file. Additionally if the message has a level higher or equal to "error" it also logs it remotely via UDP to the syslogd on en1. And additionally if the message is a panic message, it is also sent out as an Email via SMTP to the MTA on en1. Ever thought a C library has to be dull and simple? ;) PS: This stuff certainly needs more polishing and cleanup and also a few things I'll enhance in the future (for instance to remove the restriction that parameter values have to be in quotation marks, etc.). @ text @d86 2 a87 2 " prefix(prefix=\"[%d-%m-%Y/%H:%M:%S] %L test[%P]: \", timezone=\"local\")" " -> filter(regex=\"hecking\", negate=\"0\")" @ 1.43 log @Hell, I've seldom seen that it is needed to prepare and adjust such a lot of subtle details of existing code in order to make a new feature implementable in a straight-forward way. Anyway, here comes one more preparation change for the forthcoming channel tree specification parser: - change l2_util_setparam() to take an l2_env_t parameter which allows the function to report better error messages. - completely rewrite l2_util_setparam() to support calls l2_channel_configure(ch, "n1=v1,n2=v2,n3=v3") and/or l2_channel_configure(ch, "n1=%x,n2=%x,n3=%x", v1, v2, v3) instead of l2_channel_configure(ch, "n1,n2,n3", v1, v2, v3) This is both a step forward to make the interface of l2_channel_configure() more flexible (because one now can directly inline values instead of having them to be passed explicitly) and allows the spec parser not having to know the type (integer, floating point or string) of a parameter (which is important if one wants the parser to be independent of the implementing channel handlers). @ text @d63 3 d72 1 d84 13 d148 1 @ 1.42 log @More preparations for forthcoming channel tree specification parser (especially to allow the parser to determine the handler structure from a handler name without introducing another and this way redundant sub-API): - add "char *name" to l2_handler_t in order to tag each handler structure with the corresponding channel name - add l2_env_handler() function to add handler to l2_env_t objects. All l2_handler_xxxx are automatically pre-configured there after l2_env_create(). - change l2_channel_create() to take a "const char *name" (handler name) instead of the "l2_handler_t *h" (handler pointer) to make the stuff consistent and more clear. - adjust l2_test.c to reflect the changes. @ text @d34 1 a34 1 static void die(char *fmt, ...) d37 1 d42 2 a43 1 fprintf(stderr, "\n"); d69 1 d73 6 a78 6 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"); d81 2 a82 2 if ((l2_channel_create(&ch, env, "noop")) != L2_OK) die("failed to create noop channel"); d85 4 a88 5 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"); d91 4 a94 4 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"); d97 4 a100 4 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"); d103 6 a108 6 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"); d111 6 a116 7 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"); d119 6 a124 6 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"); d127 4 a130 4 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"); d133 2 a134 2 if (l2_channel_open(ch) != L2_OK) die("failed to open channel tree"); d137 8 a144 8 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"); d147 2 a148 2 if (l2_channel_destroy(ch) != L2_OK) die("failed to destroy channel tree"); @ 1.41 log @Change semantics of sibling linkage operations in order to fulfill the requirements in the forthcoming channel tree specification parser. @ text @d78 1 a78 1 if ((l2_channel_create(&ch, env, &l2_handler_noop)) != L2_OK) d82 1 a82 1 if ((l2_channel_create(&chPrefix, env, &l2_handler_prefix)) != L2_OK) d89 1 a89 1 if ((l2_channel_create(&chFilter, env, &l2_handler_filter)) != L2_OK) d95 1 a95 1 if ((l2_channel_create(&chBuffer, env, &l2_handler_buffer)) != L2_OK) d101 1 a101 1 if ((l2_channel_create(&chFile, env, &l2_handler_file)) != L2_OK) d109 1 a109 1 if ((l2_channel_create(&chSyslog, env, &l2_handler_syslog)) != L2_OK) d118 1 a118 1 if ((l2_channel_create(&chSmtp, env, &l2_handler_smtp)) != L2_OK) @ 1.40 log @Seems like my long years of programming in assembly language still have an impact on my thinking. Change "nop" (assembly mnemonic) to "noop" (english abbreviation) in the name of our no-operation channel. Thanks to Michael for catching this. @ text @d126 4 a129 4 if (l2_channel_link(ch, L2_LINK_CHILDS, chFilter, chPrefix, chBuffer, chFile, NULL) != L2_OK) die("failed to link channels together as a child sequence"); if (l2_channel_link(ch, L2_LINK_SIBLINGS, chSyslog, NULL) != L2_OK) die("failed to link filter channel on top of syslog channel"); @ 1.39 log @Simplify "null" (discard) output channel to minimum implementation and provide an additional "nop" (no-operation) filter channel for typical use as the root channel in a channel tree. @ text @d77 3 a79 3 /* create nop channel */ if ((l2_channel_create(&ch, env, &l2_handler_nop)) != L2_OK) die("failed to create nop channel"); @ 1.38 log @Channel-Only Revamping Step 2: - moved code of l2_stream.c into (new) l2_env.c and l2_channel.c - created new l2_env_t and l2_env_xxx() - changed l2_xx_create() functions to also return l2_result_t - moved error handling into l2_env_t - replaced l2_channel_stack() with two new and more flexible l2_channel_link() and l2_channel_unlink() functions - rewritten test stuff in l2_test.c to use new structure - added new l2_channel_env() function for retriving l2_env_t Puhhh.... @ text @d60 1 d77 4 d126 1 a126 1 if (l2_channel_link(chFilter, L2_LINK_CHILDS, chPrefix, chBuffer, chFile, NULL) != L2_OK) d128 1 a128 1 if (l2_channel_link(chFilter, L2_LINK_SIBLINGS, chSyslog, NULL) != L2_OK) d132 1 a132 1 if (l2_channel_open(chFilter) != L2_OK) d136 1 a136 1 if (l2_channel_log(chFilter, 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) d138 1 a138 1 if (l2_channel_log(chFilter, L2_LEVEL_PANIC, "2: Shecking\n") != L2_OK) d140 1 a140 1 if (l2_channel_log(chFilter, 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) d142 1 a142 1 if (l2_channel_log(chFilter, L2_LEVEL_PANIC, "4: Shecking\n") != L2_OK) d146 2 a147 2 if (l2_channel_destroy(chFilter) != L2_OK) die("failed to destroy stream"); @ 1.37 log @Channel-Only Revamping Step 1: allow multiple downstream channels in order to approach the later tree-like channel-only structure. @ text @d60 1 a60 1 l2_channel_t *chFilt; d62 1 a62 1 l2_channel_t *chBuf; a63 1 #ifdef WITH_SYSLOG a64 11 #endif #ifdef WITH_PIPE l2_channel_t *chPipe; #endif #ifdef WITH_SOCKET l2_channel_t *chSock; #endif #ifdef WITH_IRC l2_channel_t *chIrc; #endif #ifdef WITH_SMTP d66 1 a66 2 #endif l2_stream_t *st; d68 7 a74 5 /* * Typical steps to use a buffered file logging stream */ if ((st = l2_stream_create()) == NULL) die("failed to create stream"); d76 2 a77 1 if ((chPrefix = l2_channel_create(&l2_handler_prefix)) == NULL) /* Prefix */ d79 2 a80 2 if (l2_channel_configure(chPrefix, "prefix,timezone", "[%d-%m-%Y/%H:%M:%S] %L test[%P]: ", "local") != L2_OK) d83 2 a84 1 if ((chFilt = l2_channel_create(&l2_handler_filter)) == NULL) /* Filter */ d86 1 a86 2 if (l2_channel_configure(chFilt, "regex,negate", "hecking", 0) != L2_OK) d89 2 a90 1 if ((chBuf = l2_channel_create(&l2_handler_buffer)) == NULL) /* Buffer */ d92 1 a92 2 if (l2_channel_configure(chBuf, "size", 800) != L2_OK) d95 2 a96 1 if ((chFile = l2_channel_create(&l2_handler_file)) == NULL) /* File */ a97 1 d100 2 d103 2 a104 17 if (l2_channel_stack(chFile, chBuf) != L2_OK) die("failed to stack buffer channel on top of file channel"); if (l2_channel_stack(chBuf, chPrefix) != L2_OK) die("failed to stack prefix channel on top of buffer channel"); if (l2_channel_stack(chPrefix, chFilt) != L2_OK) die("failed to stack filter channel on top of prefix channel"); if (l2_channel_open(chFilt) != L2_OK) die("failed to open channel stack"); if (l2_stream_channel(st, chFilt, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK) die("failed to attach channel stack into stream"); #ifdef WITH_SYSLOG if ((chSyslog = l2_channel_create(&l2_handler_syslog)) == NULL) /* Syslog */ a105 1 d107 1 a107 1 "L2-Test", "user", "remote", "en1", 1) != L2_OK) d109 2 d112 2 a113 68 if (l2_channel_open(chSyslog) != L2_OK) die("failed to open channel stack"); if (l2_stream_channel(st, chSyslog, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK) die("failed to attach channel syslog into stream"); #endif /* Syslog */ #ifdef WITH_PIPE if ((chPipe = l2_channel_create(&l2_handler_pipe)) == NULL) /* Pipe */ die("failed to create pipe channel"); #if 0 if (l2_channel_configure(chPipe, "mode,path", "direct", "/u/ms/travail/cronolinux/sbin/cronolog -o /u/ms/tmp/crono.log") != L2_OK) die("failed to configure pipe channel"); #endif if (l2_channel_configure(chPipe, "execmode,path", "shell", "$CRONOLOGDIR/cronolog -o $HOME/tmp/crono.log") != L2_OK) die("failed to configure pipe channel due to mode and path parameters"); if (l2_channel_configure(chPipe, "runtime", "continuous") != L2_OK) die("failed to configure pipe channel due to continuous parameter"); if (l2_channel_open(chPipe) != L2_OK) die("failed to open pipe channel"); if (l2_stream_channel(st, chPipe, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK) die("failed to attach channel pipe into stream"); #endif /* Pipe */ #ifdef WITH_IRC /* Atenzione! Before testing IRC start the IRC server. */ if ((chIrc = l2_channel_create(&l2_handler_irc)) == NULL) /* IRC */ die("failed to create IRC channel"); if (l2_channel_configure(chIrc) != L2_OK) die("failed to configure IRC channel"); if (l2_channel_open(chIrc) != L2_OK) die("failed to open IRC channel"); if (l2_stream_channel(st, chIrc, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK) die("failed to attach channel IRC into stream"); #endif /* IRC */ #ifdef WITH_SOCKET /* Atenzione! Before doing any socket testing, make sure you have a valid */ /* end point listening, or else you will only get an error message when */ /* the thing tries to connect. */ if ((chSock = l2_channel_create(&l2_handler_socket)) == NULL) /* Socket */ die("failed to create socket channel"); if (l2_channel_configure(chSock, "proto,host,port",\ "tcp", "localhost", 2002) != L2_OK) die("failed to configure socket tcp/ipv4 channel"); #if 0 if (l2_channel_configure(chSock, "proto,host,port",\ "tcp", "0:0:0:0:0:0:0:1", 2002) != L2_OK) die("failed to configure socket tcp/ipv6 channel"); #endif if (l2_channel_open(chSock) != L2_OK) die("failed to open socket channel"); if (l2_stream_channel(st, chSock, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK) die("failed to attach channel socket into stream"); #endif /* Socket */ #ifdef WITH_SMTP if ((chSmtp = l2_channel_create(&l2_handler_smtp)) == NULL) /* SMTP */ a114 1 d117 2 d120 9 a128 9 if (l2_channel_open(chSmtp) != L2_OK) die("failed to open smtp channel"); if (l2_stream_channel(st, chSmtp, L2_LEVEL_UPTO(L2_LEVEL_ERROR), L2_LEVEL_NONE) != L2_OK) die("failed to attach smtp channel into stream"); #endif /* SMTP */ if (l2_stream_levels(st, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK) die("failed to set global logging level"); d130 9 a138 17 if (l2_stream_formatter(st, 'k', formatter, NULL) != L2_OK) die("failed to configure formatter for %%x"); if (l2_stream_formatter(st, 'S', l2_util_fmt_dump, NULL) != L2_OK) die("failed to configure formatter for %%S"); if (l2_stream_log(st, L2_LEVEL_PANIC, "0Checking 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 to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "1Shecking\n") != L2_OK) die("failed to log message to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "2Checking 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 to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "3Shecking\n") != L2_OK) die("failed to log message to stream"); d140 2 a141 1 if (l2_stream_destroy(st) != L2_OK) @ 1.36 log @- change protocol parameter from "IPPROTO_XXX" to just "xxx" - add support for numerical and textual ports - add UDP support - remove unused iSocket variable - fix massive memory leaks on channel destruction - generally simplify implementation - cleanup coding style @ text @a59 1 int i; /* For testing l2_stream_log() */ d102 1 a102 1 if (l2_channel_configure(chBuf, "size,interval", 800, 12) != L2_OK) d223 11 a233 14 while (1) { for (i = 1; i != 0; i++); if (l2_stream_log(st, L2_LEVEL_PANIC, "0Checking 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 to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "1Shecking\n") != L2_OK) die("failed to log message to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "2Checking 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 to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "3Shecking\n") != L2_OK) die("failed to log message to stream"); } @ 1.35 log @Partially rewrote the socket channel to use the OSSP socket abstraction library. Channel still needs UDP configuration and writing logic. @ text @d186 2 a187 2 if (l2_channel_configure(chSock, "protocol,host,port",\ "IPPROTO_TCP", "localhost", 2002) != L2_OK) d190 2 a191 2 if (l2_channel_configure(chSock, "protocol,host,port",\ "IPPROTO_TCP", "0:0:0:0:0:0:0:1", 2002) != L2_OK) @ 1.34 log @Completed implementation of timer. Beware of scope problem - I have only tested it, but not proven it correct. @ text @d186 2 a187 2 if (l2_channel_configure(chSock, "protocol,ipversion,host,port",\ "IPPROTO_TCP", "AF_INET", "localhost", 2002) != L2_OK) d190 2 a191 2 if (l2_channel_configure(chSock, "protocol,ipversion,host,port",\ "IPPROTO_TCP", "AF_INET6", "0:0:0:0:0:0:0:1", 2002) != L2_OK) @ 1.33 log @Changed timer from VIRTUAL to REAL. Completed flush alarm mechanism which seems to work, probably because we are not forking. @ text @d60 1 d224 14 a237 11 if (l2_stream_log(st, L2_LEVEL_PANIC, "0Checking 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 to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "1Shecking\n") != L2_OK) die("failed to log message to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "2Checking 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 to stream"); if (l2_stream_log(st, L2_LEVEL_PANIC, "3Shecking\n") != L2_OK) die("failed to log message to stream"); @ 1.32 log @Added untested code to implement alarm exceptions in the buffer channel. The buffer will auto-flush after a user specified timeout if it is even possible to do this with a c-style exception handler. @ text @d102 1 a102 1 if (l2_channel_configure(chBuf, "size,interval", 100, 20) != L2_OK) d223 10 a232 1 if (l2_stream_log(st, L2_LEVEL_PANIC, "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) @ 1.31 log @Birth of IRC channel. @ text @d102 1 a102 1 if (l2_channel_configure(chBuf, "size", 100) != L2_OK) @ 1.30 log @More socket channel configuration parameter adjustments. @ text @d73 3 d162 15 @ 1.29 log @Pipe and socket channel configuration-time parameter improvements. @ text @d168 1 a168 1 "tcp", "ipv4", "localhost", 2002) != L2_OK) d172 1 a172 1 "tcp", "ipv6", "0:0:0:0:0:0:0:1", 2002) != L2_OK) @ 1.28 log @Fixed bug of incorrectly checking the result of a call to pcre_study(), and later testing the return of pcre_exec(). Added code to test the filter channel. @ text @a31 6 #include /* following group of includes are for */ #include /* socket testing only */ #include #include /* TODO: probably can be removed */ #include /* TODO: probably can be removed */ d147 5 a151 2 if (l2_channel_configure(chPipe, "mode,path", "shell", "$CRONOLOGDIR/cronolog -o $HOME/tmp/crono.log") != L2_OK) die("failed to configure pipe channel"); d168 2 a169 2 IPPROTO_TCP, AF_INET, "localhost", 2002) != L2_OK) die("failed to configure socket ipv4 channel"); d172 2 a173 2 IPPROTO_TCP, AF_INET6, "0:0:0:0:0:0:0:1", 2002) != L2_OK) die("failed to configure socket ipv6 channel"); @ 1.27 log @Followup this suspicion later to remove unnecessary junk. @ text @d66 1 d96 6 d120 4 a123 1 if (l2_channel_open(chPrefix) != L2_OK) d126 1 a126 1 if (l2_stream_channel(st, chPrefix, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK) @ 1.26 log @New implementation of signal handler and process control logic, improved reliability, some redesign, and test logic. @ text @d35 2 a36 4 #include #include #include /* unistd and fcntl included for pipes */ #include @ 1.25 log @Fixed missing ifdef WITH_SOCKET. @ text @d134 1 a134 1 #endif d140 6 a145 1 if (l2_channel_configure(chPipe, "pipe", pipdesc[1]) != L2_OK) d153 1 a153 1 #endif d175 1 a175 1 #endif d189 1 a189 1 #endif @ 1.24 log @Pipe channel handler redesign, bugfixes, and cleanup. @ text @d77 1 d79 1 @ 1.23 log @Revamp Syslog output channel. It now fully supports local _AND_ remote logging. The local variant is still based on syslog(3), the remote variant is based on manual network connections with the syslog protocol as defined in RFC3164. @ text @d37 1 a37 1 #include a76 1 #ifdef WITH_SOCKET a77 1 #endif a82 1 int pipdesc[2]; /* For use with our pipe channel test */ a85 1 a88 22 #ifdef WITH_SOCKET /* Atenzione! Before doing any socket testing, make sure you have a valid */ /* end point listening, or else you will only get an error message when */ /* the thing tries to connect. */ if ((chSock = l2_channel_create(&l2_handler_socket)) == NULL) die("failed to create socket channel"); if (l2_channel_configure(chSock, "protocol,ipversion,host,port",\ IPPROTO_TCP, AF_INET, "localhost", 2002) != L2_OK) die("failed to configure socket ipv4 channel"); #if 0 if (l2_channel_configure(chSock, "protocol,ipversion,host,port",\ IPPROTO_TCP, AF_INET6, "0:0:0:0:0:0:0:1", 2002) != L2_OK) die("failed to configure socket ipv6 channel"); #endif if (l2_channel_open(chSock) != L2_OK) die("failed to open socket channel"); if (l2_stream_channel(st, chSock, L2_LEVEL_UPTO(L2_LEVEL_WARNING), L2_LEVEL_NONE) != L2_OK) die("failed to attach first channel into stream"); #endif d95 1 a95 1 if ((chBuf = l2_channel_create(&l2_handler_buffer)) == NULL) /* Buffer */ d101 1 a101 1 if ((chFile = l2_channel_create(&l2_handler_file)) == NULL) /* File */ a106 11 #ifdef WITH_PIPE if (pipe(pipdesc)) die("pipe() call failed"); if ((chPipe = l2_channel_create(&l2_handler_pipe)) == NULL) /* Pipe */ die("failed to create pipe channel"); if (l2_channel_configure(chPipe, "pipe", pipdesc[1]) != L2_OK) die("failed to configure pipe channel"); #endif a112 5 #ifdef WITH_PIPE if (l2_channel_stack(chPrefix, chPipe) != L2_OK) die("failed to stack pipe channel on top of prefix channel"); #endif d120 1 a120 1 if ((chSyslog = l2_channel_create(&l2_handler_syslog)) == NULL) /* Syslog */ d134 36 d171 1 a171 1 if ((chSmtp = l2_channel_create(&l2_handler_smtp)) == NULL) /* SMTP */ a198 2 close(pipdesc[1]); /* Close the locally made pipe file descriptor */ close(pipdesc[0]); /* Close the locally made pipe file descriptor */ @ 1.22 log @wrap things with WITH_XXX @ text @d165 2 a166 2 if (l2_channel_configure(chSyslog, "ident,facility,target", "L2-Test", "user", "local") != L2_OK) @ 1.21 log @Added the Thomas signal handler to catch SIGCHLD and SIGPIPE, pipe handler is now a filter not an output, new logic to test code, bugfixes. @ text @d71 1 d73 2 d76 1 d133 1 d142 1 d150 1 d153 1 d161 1 d165 3 a167 4 if (l2_channel_configure(chSyslog, "ident,logopts,facility,priority,maskpriority",\ "Test", (LOG_PID | LOG_CONS), LOG_USER, (LOG_CRIT|LOG_ALERT|LOG_NOTICE),\ 0xFFFFFFFF) != L2_OK) die("failed to configure file channel"); d174 1 @ 1.20 log @Added debug infrastructure, assertions, fixed one bug. @ text @d37 2 d72 1 d81 1 d129 9 d144 3 d196 2 @ 1.19 log @First cut for flush mask support. @ text @d103 1 a103 1 if (l2_stream_channel(st, chSock, L2_LEVEL_UPTO(L2_LEVEL_WARNING)) != L2_OK) @ 1.18 log @add support for %L (level) and %P (pid) to prefix channel @ text @d134 1 a134 1 if (l2_stream_channel(st, chPrefix, L2_LEVEL_UPTO(L2_LEVEL_WARNING)) != L2_OK) d148 1 a148 1 if (l2_stream_channel(st, chSyslog, L2_LEVEL_UPTO(L2_LEVEL_WARNING)) != L2_OK) d161 1 a161 1 if (l2_stream_channel(st, chSmtp, L2_LEVEL_UPTO(L2_LEVEL_ERROR)) != L2_OK) d165 1 a165 1 if (l2_stream_levels(st, L2_LEVEL_UPTO(L2_LEVEL_WARNING)) != L2_OK) @ 1.17 log @Added provisional testing of syslog channel. Once syslog is trimmed or redesigned, this test code will reflect the changes. @ text @d110 1 a110 1 if (l2_channel_configure(chPrefix, "timefmt,timezone", "[%d-%m-%Y/%H:%M:%S] ", "local") != L2_OK) @ 1.16 log @Cleanup socket stuff and add SMTP test. @ text @d36 1 d69 1 d93 1 a93 1 IPPROTO_UDP, AF_INET, "localhost", 2002) != L2_OK) d136 14 @ 1.15 log @do not use C++ comments @ text @d68 1 d70 4 d83 4 a86 3 /* Atenzione! Before doing any socket testing, make sure you have a valid */ /* end point listening, or else you will only get an error message when */ /* the thing tries to connect. */ d93 2 a94 2 /* if (l2_channel_configure(chSock, "protocol,ipversion,host,port",\ d96 2 a97 2 die("failed to configure socket ipv6 channel"); */ d103 1 d134 14 @ 1.14 log @More kludges to test sockets UDP and IPv6. @ text @d88 3 a90 3 // if (l2_channel_configure(chSock, "protocol,ipversion,host,port",\ // IPPROTO_TCP, AF_INET6, "0:0:0:0:0:0:0:1", 2002) != L2_OK) // die("failed to configure socket ipv6 channel"); @ 1.13 log @Add two cool extra formatter functions ;) l2_util_fmt_string: This can be used like %s, but instead of fetching only a "char *" from the var-args stack, it fetches a "char *" plus a "size_t" and this way allows one to log only a sub-string of a larger string without the need for any temporary buffers, etc. l2_util_fmt_dump: This can be used as "%{type}X" for dumping arbitrary octets. The parameter "type" can be either "text" (the default if only "%X" is used) for dumping the octets as text but with non-printable characters replaced by "\xXX" constructs; "hex" for dumping the octets in hexadecimal as "XX:XX:XX:XX" or "base64" for dumping the octets Base64 encoded. All three are intended for making it easier to produce reasonable L2_LEVEL_DEBUG messages without having to fiddle around with temporary buffers and having to care with non-printable characters. For instance, using... : l2_stream_formatter(st, 'D', l2_util_fmt_dump, NULL); : l2_stream_vlog(st, L2_LEVEL_DEBUG, "%{text}D %{hex}D %{base64}D\n", "foo", 12345, "foo\1bar", 7, "foo\1bar", 7, "foo\1bar", 7); : ...produces "foo\x01bar 66:6f:6f:01:62:61:72 Zm9vAWJhcg==" in the output. @ text @d81 1 a81 1 /* if ((chSock = l2_channel_create(&l2_handler_socket)) == NULL) d84 2 a85 2 if (l2_channel_configure(chSock, "ipversion,host,port", AF_INET,\ "localhost", 2002) != L2_OK) d88 3 a90 3 if (l2_channel_configure(chSock, "ipversion,host,port", AF_INET6,\ "0123:4567:4455:6677:8899:AABB:9876:5432", 2002) != L2_OK) die("failed to configure socket ipv6 channel"); a96 1 */ @ 1.12 log @Implemented prefix channel plus mini test. @ text @d135 4 a138 1 if (l2_stream_log(st, L2_LEVEL_PANIC, "Checking localhost %s %{myparm}k\n", "foo", 12345) != L2_OK) @ 1.11 log @Array bug fixes and code to test sockets. @ text @d65 1 d98 7 d119 3 d123 2 a124 2 if (l2_channel_open(chBuf) != L2_OK) die("failed to open buffer channel"); d126 2 a127 2 if (l2_stream_channel(st, chBuf, L2_LEVEL_UPTO(L2_LEVEL_WARNING)) != L2_OK) die("failed to attach second channel into stream"); @ 1.10 log @cleanup level API (no need for retrieving old mask just in one function - either in all or in none). @ text @d31 6 d67 1 d74 24 a97 1 if ((chBuf = l2_channel_create(&l2_handler_buffer)) == NULL) a99 3 if ((chFile = l2_channel_create(&l2_handler_file)) == NULL) die("failed to create file channel"); d103 3 a114 3 if ((st = l2_stream_create()) == NULL) die("failed to create stream"); d116 1 a116 1 die("failed to attach channel into stream"); d124 1 a124 1 if (l2_stream_log(st, L2_LEVEL_PANIC, "test %s %{foo}k", "foo", 12345) != L2_OK) @ 1.9 log @make static @ text @d91 1 a91 1 if (l2_stream_levels(st, L2_LEVEL_UPTO(L2_LEVEL_WARNING), NULL) != L2_OK) @ 1.8 log @Much more beautiful formatter callback (whitespace cleanup.) @ text @d45 3 a47 2 l2_result_t formatter(l2_context_t *ctx, const char id, const char *param, char *bufptr, size_t bufsize, size_t *buflen, va_list *ap) @ 1.7 log @Bugfixes and new format testing. @ text @d45 2 a46 9 l2_result_t formatter( l2_context_t *ctx, const char id, const char *param, char *bufptr, size_t bufsize, size_t *buflen, va_list *ap ) @ 1.6 log @- replace "int" with "l2_result_t" in L2 channel API - use a 2^n for L2_LEVEL_XXX in order to be able to create mask - remember loglevel for each channel - rewrite test suite @ text @d45 18 d100 4 a103 1 if (l2_stream_log(st, L2_LEVEL_PANIC, "test %s", "foo") != L2_OK) @ 1.5 log @Added configuration and opening of buffer and file channels. @ text @d33 12 d46 41 a86 60 { l2_channel_t* log_channel_buf; l2_channel_t* log_channel_file; l2_stream_t* log_stream; /* Create the channel. */ setbuf(stdout, 0); printf("Creating channel ... "); log_channel_buf = l2_channel_create(&l2_handler_buffer); log_channel_file = l2_channel_create(&l2_handler_file); if ((log_channel_buf == 0) || (log_channel_file == 0)) { fprintf(stderr, "Can't create my log channels!\n"); return 1; } printf("done\n"); l2_channel_configure(log_channel_buf, "size", 100); l2_channel_configure(log_channel_file, "path", "myfilelog", "append",\ TRUE, "perm", 0x644); l2_channel_open(log_channel_buf); l2_channel_open(log_channel_file); /* Create the stream and attach the channel to it. */ printf("Creating stream ... "); log_stream = l2_stream_create(); if (log_stream == 0) { fprintf(stderr, "Can't create my log stream!\n"); return 1; } printf("done\n"); printf("Attaching channel to stream ... "); if (!l2_stream_channel(log_stream, log_channel_buf, -1)) { fprintf(stderr, "Can't attach buffer channel to log stream!\n"); return 1; } if (!l2_stream_channel(log_stream, log_channel_file, -1)) { fprintf(stderr, "Can't attach file channel to log stream!\n"); return 1; } printf("done\n"); /* Log an example message. */ printf("Writing log message ... "); l2_stream_log(log_stream, -1, "%cstream = 0x%lx, channel = 0x%lx%c\n", '"',\ log_stream, log_channel_buf, '"'); printf("done\n"); /* Clean up. */ printf("Destroying stream ... "); l2_stream_destroy(log_stream); printf("done\n"); d89 2 a90 1 } @ 1.4 log @Fix more ossp.com references by replacing with the correct domain name ossp.org. @ text @d35 2 a36 1 l2_channel_t* log_channel; d43 3 a45 2 log_channel = l2_channel_create(&l2_handler_syslog); if (log_channel == 0) d47 1 a47 1 fprintf(stderr, "Can't create my log channel!\n"); d52 7 d70 6 a75 1 if (!l2_stream_channel(log_stream, log_channel, -1)) d77 1 a77 1 fprintf(stderr, "Can't attach channel to log stream!\n"); d85 2 a86 1 l2_stream_log(log_stream, -1, "%cstream = 0x%lx, channel = 0x%lx%c", '"', log_stream, log_channel, '"'); @ 1.3 log @Wrote a small test program for the library. @ text @d7 1 a7 1 ** can be found at http://www.ossp.com/pkg/l2/. @ 1.2 log @- Add copyrights - use l2++.h in C++ test @ text @d30 1 d34 46 a79 1 { d81 1 a81 2 } @ 1.1 log @Initial revision @ text @d1 28 @ 1.1.1.1 log @L2 initial source tree @ text @@