1/*
2  Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
3
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  GNU General Public License for more details.
13*/
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif /* HAVE_CONFIG_H */
18
19#include <stdio.h>
20#include <stdbool.h>
21
22#include <atalk/logger.h>
23
24int main(int argc, char *argv[])
25{
26  set_processname("logger_Test");
27#if 0
28  LOG(log_severe, logtype_logger, "Logging Test starting: this should only log to syslog");
29
30  /* syslog testing */
31  LOG(log_severe, logtype_logger, "Disabling syslog logging.");
32  unsetuplog("Default");
33  LOG(log_error, logtype_default, "This shouldn't log to syslog: LOG(log_error, logtype_default).");
34  LOG(log_error, logtype_logger, "This shouldn't log to syslog: LOG(log_error, logtype_logger).");
35  setuplog("Default LOG_INFO");
36  LOG(log_info, logtype_logger, "Set syslog logging to 'log_info', so this should log again. LOG(log_info, logtype_logger).");
37  LOG(log_error, logtype_logger, "This should log to syslog: LOG(log_error, logtype_logger).");
38  LOG(log_error, logtype_default, "This should log to syslog. LOG(log_error, logtype_default).");
39  LOG(log_debug, logtype_logger, "This shouldn't log to syslog. LOG(log_debug, logtype_logger).");
40  LOG(log_debug, logtype_default, "This shouldn't log to syslog. LOG(log_debug, logtype_default).");
41  LOG(log_severe, logtype_logger, "Disabling syslog logging.");
42  unsetuplog("Default");
43#endif
44  /* filelog testing */
45
46  setuplog("DSI:maxdebug", "test.log");
47  LOG(log_info, logtype_dsi, "This should log.");
48  LOG(log_error, logtype_default, "This should not log.");
49
50  setuplog("Default:debug", "test.log");
51  LOG(log_debug, logtype_default, "This should log.");
52  LOG(log_maxdebug, logtype_default, "This should not log.");
53
54  LOG(log_maxdebug, logtype_dsi, "This should still log.");
55
56  /* flooding prevention check */
57  LOG(log_debug, logtype_default, "Flooding 3x");
58  for (int i = 0; i < 3; i++) {
59      LOG(log_debug, logtype_default, "Flooding...");
60  }
61  /* wipe the array */
62  LOG(log_debug, logtype_default, "1"); LOG(log_debug, logtype_default, "2"); LOG(log_debug, logtype_default, "3");
63
64  LOG(log_debug, logtype_default, "-============");
65  LOG(log_debug, logtype_default, "Flooding 5x");
66  for (int i = 0; i < 5; i++) {
67      LOG(log_debug, logtype_default, "Flooding...");
68  }
69  LOG(log_debug, logtype_default, "1"); LOG(log_debug, logtype_default, "2"); LOG(log_debug, logtype_default, "3");
70
71  LOG(log_debug, logtype_default, "o============");
72  LOG(log_debug, logtype_default, "Flooding 2005x");
73  for (int i = 0; i < 2005; i++) {
74      LOG(log_debug, logtype_default, "Flooding...");
75  }
76  LOG(log_debug, logtype_default, "1"); LOG(log_debug, logtype_default, "2"); LOG(log_debug, logtype_default, "3");
77
78  LOG(log_debug, logtype_default, "0============");
79  LOG(log_debug, logtype_default, "Flooding 11x1");
80  for (int i = 0; i < 11; i++) {
81      LOG(log_error, logtype_default, "flooding 11x1 1");
82  }
83
84  LOG(log_debug, logtype_default, "1============");
85  LOG(log_debug, logtype_default, "Flooding 11x2");
86  for (int i = 0; i < 11; i++) {
87      LOG(log_error, logtype_default, "flooding 11x2 1");
88      LOG(log_error, logtype_default, "flooding 11x2 2");
89  }
90
91  LOG(log_debug, logtype_default, "2============");
92  LOG(log_debug, logtype_default, "Flooding 11x3");
93  for (int i = 0; i < 11; i++) {
94      LOG(log_error, logtype_default, "flooding 11x3 1");
95      LOG(log_error, logtype_default, "flooding 11x3 2");
96      LOG(log_error, logtype_default, "flooding 11x3 3");
97  }
98
99  LOG(log_debug, logtype_default, "3============");
100  LOG(log_debug, logtype_default, "Flooding 11x4");
101  for (int i = 0; i < 11; i++) {
102      LOG(log_error, logtype_default, "flooding 11x4 1");
103      LOG(log_error, logtype_default, "flooding 11x4 2");
104      LOG(log_error, logtype_default, "flooding 11x4 3");
105      LOG(log_error, logtype_default, "flooding 11x4 4");
106  }
107
108
109  return 0;
110}
111
112
113