New option -w sec for test log utility
[yaz-moved-to-github.git] / test / tstlog.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: tstlog.c,v 1.8 2005-09-16 21:14:38 adam Exp $
6  *
7  */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <yaz/options.h>
11 #include <yaz/log.h>
12 #if HAVE_UNISTD_H
13 #include <unistd.h>
14 #endif
15
16 int main(int argc, char **argv)
17 {
18     char *arg;
19     int i, ret;
20     int level = YLOG_LOG;
21     int number = 1;
22     unsigned int wait_between_log = 0;
23
24     while ((ret = options("f:v:l:m:n:s:w:", argv, argc, &arg)) != -2)
25     {
26         switch (ret)
27         {
28         case 's':
29             yaz_log_init_max_size(atoi(arg));
30             break;
31         case 'f':
32             yaz_log_time_format(arg);
33             break;
34         case 'v':
35             yaz_log_init_level(yaz_log_mask_str(arg));
36             break;
37         case 'l':
38             yaz_log_init_file(arg);
39             break;
40         case 'n':
41             number = atoi(arg);
42             break;
43         case 'm':        
44             level = yaz_log_module_level(arg);
45             break;
46         case 'w':
47             wait_between_log = atoi(arg);
48             break;
49         case 0:
50             for (i = 0; i<number; i++)
51             {
52                 yaz_log(level, "%d %s", i, arg);
53 #if HAVE_UNISTD_H
54                 if (wait_between_log)
55                     sleep(wait_between_log);
56 #endif
57             }
58             break;
59         default:
60             fprintf(stderr, "tstlog. Bad option\n");
61             fprintf(stderr, "tstlog [-f logformat] [-v level] [-l file] "
62                     "[-m module] [-w sec] [-s max] [-n num] msg ..\n");
63             exit(1);
64         }
65     }
66     exit(0);
67 }
68 /*
69  * Local variables:
70  * c-basic-offset: 4
71  * indent-tabs-mode: nil
72  * End:
73  * vim: shiftwidth=4 tabstop=8 expandtab
74  */
75