Ignore zoomst10
[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.10 2006-03-21 12:54:02 adam Exp $
6  *
7  */
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <yaz/options.h>
12 #include <yaz/log.h>
13 #if HAVE_UNISTD_H
14 #include <unistd.h>
15 #endif
16
17 void hook_func(int level, const char *msg, void *vp)
18 {
19     fprintf(stderr, "[HOOK level=%d msg=%s]\n", level, msg);
20 }
21
22 int main(int argc, char **argv)
23 {
24     char *arg;
25     int i, ret;
26     int level = YLOG_LOG;
27     int number = 1;
28     unsigned int wait_between_log = 0;
29
30     while ((ret = options("f:v:l:m:n:s:w:Hh", argv, argc, &arg)) != -2)
31     {
32         switch (ret)
33         {
34         case 's':
35             yaz_log_init_max_size(atoi(arg));
36             break;
37         case 'f':
38             yaz_log_time_format(arg);
39             break;
40         case 'v':
41             yaz_log_init_level(yaz_log_mask_str(arg));
42             break;
43         case 'l':
44             if (!strcmp(arg, "@"))
45                 yaz_log_init_file(0);
46             else
47                 yaz_log_init_file(arg);
48             break;
49         case 'n':
50             number = atoi(arg);
51             break;
52         case 'm':        
53             level = yaz_log_module_level(arg);
54             break;
55         case 'w':
56             wait_between_log = atoi(arg);
57             break;
58         case 'H':
59             yaz_log_set_handler(hook_func, 0);
60             break;
61         case 0:
62             for (i = 0; i<number; i++)
63             {
64                 yaz_log(level, "%d %s", i, arg);
65 #if HAVE_UNISTD_H
66                 if (wait_between_log)
67                     sleep(wait_between_log);
68 #endif
69             }
70             break;
71         case 'h':
72         default:
73             fprintf(stderr, "tstlog. Bad option\n");
74             fprintf(stderr, "tstlog [-f logformat] [-v level] [-l file] "
75                     "[-m module] [-w sec] [-s max] [-n num] [-H] msg ..\n");
76             exit(1);
77         }
78     }
79     exit(0);
80 }
81 /*
82  * Local variables:
83  * c-basic-offset: 4
84  * indent-tabs-mode: nil
85  * End:
86  * vim: shiftwidth=4 tabstop=8 expandtab
87  */
88