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1_6:1.2 FSL_0_1_5:1.2 FSL_0_1_1:1.2 LMTP2NNTP_1_2a5:1.2 LMTP2NNTP_1_2a4:1.2 LMTP2NNTP_1_2a3:1.2 LMTP2NNTP_1_2a1:1.1; locks; strict; comment @ * @; 1.8 date 2005.10.03.08.08.11; author rse; state Exp; branches; next 1.7; 1.7 date 2005.02.03.09.43.52; author rse; state Exp; branches; next 1.6; 1.6 date 2005.01.24.15.03.18; author rse; state Exp; branches; next 1.5; 1.5 date 2003.09.25.13.12.06; author thl; state Exp; branches; next 1.4; 1.4 date 2003.01.06.11.41.52; author rse; state Exp; branches; next 1.3; 1.3 date 2002.07.30.19.08.25; author rse; state Exp; branches; next 1.2; 1.2 date 2002.01.02.17.07.38; author rse; state Exp; branches; next 1.1; 1.1 date 2001.11.10.14.01.47; author rse; state Exp; branches; next ; desc @@ 1.8 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. ** ** l2tool.c: command line tool */ #include #include "l2.h" #include static void die(l2_env_t *env, l2_result_t rv, char *fmt, ...) { va_list ap; char *error; va_start(ap, fmt); fprintf(stderr, "l2tool:ERROR: "); vfprintf(stderr, fmt, ap); error = l2_env_strerror(env, rv); fprintf(stderr, " (%s)\n", error); va_end(ap); exit(1); } static void usage(void) { fprintf(stderr, "l2tool:ERROR: invalid command line\n"); fprintf(stderr, "l2tool:USAGE: l2tool [-s sleepsec] \n"); exit(1); } int main(int argc, char *argv[]) { l2_channel_t *ch; char *spec; l2_result_t rv; l2_env_t *env; char *cpLevel; char caBuf[2048]; int nBuf; char *cpMsg; char *cp; unsigned int nLevel; int option; int nSleep = 0; /* command line parsing */ while ((option = getopt(argc, argv, "s:")) != EOF) { switch ((char) option) { case 's': nSleep = atoi(optarg); break; default: usage(); /* NOTREACHED */ } } if (argc - optind != 1) usage(); spec = argv[optind]; /* create environment */ if ((rv = l2_env_create(&env)) != L2_OK) die(env, rv, "failed to create environment"); /* create channel tree */ if ((rv = l2_spec(&ch, env, spec)) != L2_OK) die(env, rv, "failed to parse specification"); /* open channel tree */ if ((rv = l2_channel_open(ch)) != L2_OK) die(env, rv, "failed to open channel tree"); /* loop over stdin */ while (fgets(caBuf, sizeof(caBuf), stdin) != NULL) { /* strip newline */ nBuf = strlen(caBuf); caBuf[nBuf-1] = '\0'; /* parse logging level */ nLevel = L2_LEVEL_INFO; cpLevel = "info"; cpMsg = caBuf; if (caBuf[0] == '<') { if ((cp = strchr(caBuf+1, '>')) == NULL) die(env, rv, "unterminated level prefix"); *cp++ = '\0'; cpLevel = caBuf+1; cpMsg = cp; } if (l2_util_s2l(cpLevel, strlen(cpLevel), ',', &nLevel) != L2_OK) die(env, rv, "invalid level prefix"); /* perform log operation(s) */ if ((rv = l2_channel_log(ch, nLevel, "%s", cpMsg)) != L2_OK) die(env, rv, "failed to log message to channel tree"); /* artifical delay */ sleep(nSleep); } /* 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.7 log @Remove local getopt() declarations from l2tool.c for portability. @ 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.6 log @Adjust copyright messages for new year 2005. @ text @a34 3 extern int getopt(int, char *const *, const char *); extern int optind; extern char *optarg; @ 1.5 log @enhance command line parsing and add "-s sleepsec" 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.4 log @- remove trailing whitespaces - adjust copyright messages - consistently use "OSSP l2" - consistently talk about "Flexible Logging" - use standard OSSP ASCII-art @ text @d34 5 d53 7 d72 2 d75 10 a84 5 /* minimal command line parsing */ if (argc != 2) { fprintf(stderr, "l2tool:ERROR: invalid command line\n"); fprintf(stderr, "l2tool:USAGE: l2tool \n"); exit(1); d86 3 a88 1 spec = argv[1]; d125 3 @ 1.3 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 d28 1 a28 1 ** l2tool.c: L2 command line tool d80 1 a80 1 @ 1.2 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/. @ 1.1 log @First cut for the L2 command line tool which allows us very easy testing through the new channel tree specification parser. @ 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/) @