]> mj.ucw.cz Git - libucw.git/blob - ucw/shell/ucw-logger.c
d9aa1fe8ccd3fba5baa6a5cfb9c21c8d1bb8b541
[libucw.git] / ucw / shell / ucw-logger.c
1 /*
2  *      UCW Library Utilities -- A Simple Logger for use in shell scripts
3  *
4  *      (c) 2001--2009 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include <ucw/lib.h>
11 #include <ucw/log.h>
12
13 #include <stdio.h>
14 #include <string.h>
15
16 int
17 main(int argc, char **argv)
18 {
19   byte buf[1024], *c;
20
21   log_init("ucw-logger");
22   if (argc < 3 || argc > 4 || strlen(argv[2]) != 1)
23     die("Usage: ucw-logger [<logname>:]<progname> <level> [<text>]");
24   if (c = strchr(argv[1], ':'))
25     {
26       *c++ = 0;
27       log_init(c);
28       log_file(argv[1]);
29     }
30   else
31     log_init(argv[1]);
32
33   uns level = 0;
34   while (level < L_MAX && LS_LEVEL_LETTER(level) != argv[2][0])
35     level++;
36   if (level >= L_MAX)
37     die("Unknown logging level `%s'", argv[2]);
38
39   if (argc > 3)
40     msg(level, "%s", argv[3]);
41   else
42     while (fgets(buf, sizeof(buf), stdin))
43       {
44         c = strchr(buf, '\n');
45         if (c)
46           *c = 0;
47         msg(level, "%s", buf);
48       }
49   return 0;
50 }