]> mj.ucw.cz Git - libucw.git/blob - lib/shell/logger.c
Moved shell script support commands to lib/shell.
[libucw.git] / lib / shell / logger.c
1 /*
2  *      Sherlock Utilities -- A Simple Logger for use in shell scripts
3  *
4  *      (c) 2001 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "lib/lib.h"
8
9 #include <stdio.h>
10 #include <string.h>
11
12 int
13 main(int argc, char **argv)
14 {
15   byte buf[1024], *c;
16
17   log_init("logger");
18   if (argc < 3 || argc > 4 || strlen(argv[2]) != 1)
19     die("Usage: logger [<logname>:]<progname> <level> [<text>]");
20   if (c = strchr(argv[1], ':'))
21     {
22       *c++ = 0;
23       log_init(c);
24       log_file(argv[1]);
25     }
26   else
27     log_init(argv[1]);
28   if (argc > 3)
29     log(argv[2][0], argv[3]);
30   else
31     while (fgets(buf, sizeof(buf), stdin))
32       {
33         c = strchr(buf, '\n');
34         if (c)
35           *c = 0;
36         log(argv[2][0], buf);
37       }
38   return 0;
39 }