Add sample experimental patch to show "make apply", "make unapply", "make patchlist...
[asterisk/asterisk.git] / patches / queue_log
1 Index: logger.c
2 ===================================================================
3 RCS file: /usr/cvsroot/asterisk/logger.c,v
4 retrieving revision 1.55
5 diff -u -r1.55 logger.c
6 --- logger.c    25 Jan 2005 06:10:19 -0000      1.55
7 +++ logger.c    9 Mar 2005 21:25:25 -0000
8 @@ -61,6 +61,11 @@
9  static int pending_logger_reload = 0;
10  static int global_logmask = -1;
11  
12 +static struct {
13 +       unsigned int queue_log:1;
14 +       unsigned int event_log:1;
15 +} logfiles = { 1, 1 };
16 +
17  static struct msglist {
18         char *msg;
19         struct msglist *next;
20 @@ -288,6 +293,13 @@
21                 strncpy(dateformat, s, sizeof(dateformat) - 1);
22         } else
23                 strncpy(dateformat, "%b %e %T", sizeof(dateformat) - 1);
24 +       if ((s = ast_variable_retrieve(cfg, "general", "queue_log"))) {
25 +               logfiles.queue_log = ast_true(s);
26 +       }
27 +       if ((s = ast_variable_retrieve(cfg, "general", "event_log"))) {
28 +               logfiles.event_log = ast_true(s);
29 +       }
30 +
31         var = ast_variable_browse(cfg, "logfiles");
32         while(var) {
33                 chan = make_logchannel(var->name, var->value, var->lineno);
34 @@ -332,7 +344,9 @@
35                 qlog = NULL;
36         }
37         snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_LOG_DIR, "queue_log");
38 -       qlog = fopen(filename, "a");
39 +       if (logfiles.queue_log) {
40 +               qlog = fopen(filename, "a");
41 +       }
42         ast_mutex_unlock(&qloglock);
43         if (reloaded) 
44                 ast_queue_log("NONE", "NONE", "NONE", "CONFIGRELOAD", "%s", "");
45 @@ -360,22 +374,24 @@
46         mkdir((char *)ast_config_AST_LOG_DIR, 0755);
47         snprintf(old, sizeof(old), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
48  
49 -       if(rotate) {
50 -               for(x=0;;x++) {
51 -                       snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
52 -                       myf = fopen((char *)new, "r");
53 -                       if(myf) 
54 -                               fclose(myf);
55 -                       else
56 -                               break;
57 -               }
58 +       if (logfiles.event_log) {
59 +               if (rotate) {
60 +                       for (x=0;;x++) {
61 +                               snprintf(new, sizeof(new), "%s/%s.%d", (char *)ast_config_AST_LOG_DIR, EVENTLOG,x);
62 +                               myf = fopen((char *)new, "r");
63 +                               if (myf) 
64 +                                       fclose(myf);
65 +                               else
66 +                                       break;
67 +                       }
68         
69 -               /* do it */
70 -               if (rename(old,new))
71 -                       fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
72 -       }
73 +                       /* do it */
74 +                       if (rename(old,new))
75 +                               fprintf(stderr, "Unable to rename file '%s' to '%s'\n", old, new);
76 +               }
77  
78 -       eventlog = fopen(old, "a");
79 +               eventlog = fopen(old, "a");
80 +       }
81  
82         f = logchannels;
83         while(f) {
84 @@ -406,16 +422,17 @@
85         ast_mutex_unlock(&loglock);
86  
87         queue_log_init();
88 -
89 -       if (eventlog) {
90 -               init_logger_chain();
91 -               ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
92 -               if (option_verbose)
93 -                       ast_verbose("Asterisk Event Logger restarted\n");
94 -               return 0;
95 -       } else 
96 -               ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
97         init_logger_chain();
98 +
99 +       if (logfiles.event_log) {
100 +               if (eventlog) {
101 +                       ast_log(LOG_EVENT, "Restarted Asterisk Event Logger\n");
102 +                       if (option_verbose)
103 +                               ast_verbose("Asterisk Event Logger restarted\n");
104 +                       return 0;
105 +               } else 
106 +                       ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
107 +       }
108         pending_logger_reload = 0;
109         return -1;
110  }
111 @@ -487,21 +504,23 @@
112         /* initialize queue logger */
113         queue_log_init();
114  
115 -       /* create the eventlog */
116 -       mkdir((char *)ast_config_AST_LOG_DIR, 0755);
117 -       snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
118 -       eventlog = fopen((char *)tmp, "a");
119 -       if (eventlog) {
120 -               init_logger_chain();
121 -               ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
122 -               if (option_verbose)
123 -                       ast_verbose("Asterisk Event Logger Started %s\n",(char *)tmp);
124 -               return 0;
125 -       } else 
126 -               ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
127 -
128         /* create log channels */
129         init_logger_chain();
130 +
131 +       /* create the eventlog */
132 +       if (logfiles.event_log) {
133 +               mkdir((char *)ast_config_AST_LOG_DIR, 0755);
134 +               snprintf(tmp, sizeof(tmp), "%s/%s", (char *)ast_config_AST_LOG_DIR, EVENTLOG);
135 +               eventlog = fopen((char *)tmp, "a");
136 +               if (eventlog) {
137 +                       ast_log(LOG_EVENT, "Started Asterisk Event Logger\n");
138 +                       if (option_verbose)
139 +                               ast_verbose("Asterisk Event Logger Started %s\n",(char *)tmp);
140 +                       return 0;
141 +               } else 
142 +                       ast_log(LOG_ERROR, "Unable to create event log: %s\n", strerror(errno));
143 +       }
144 +
145         return -1;
146  }
147  
148 @@ -572,7 +591,7 @@
149         localtime_r(&t, &tm);
150         strftime(date, sizeof(date), dateformat, &tm);
151  
152 -       if (level == __LOG_EVENT) {
153 +       if (logfiles.event_log && level == __LOG_EVENT) {
154                 va_start(ap, fmt);
155  
156                 fprintf(eventlog, "%s asterisk[%d]: ", date, getpid());
157 Index: configs/logger.conf.sample
158 ===================================================================
159 RCS file: /usr/cvsroot/asterisk/configs/logger.conf.sample,v
160 retrieving revision 1.9
161 diff -u -r1.9 logger.conf.sample
162 --- configs/logger.conf.sample  5 Sep 2004 03:48:05 -0000       1.9
163 +++ configs/logger.conf.sample  9 Mar 2005 21:25:25 -0000
164 @@ -13,6 +13,12 @@
165  ; This appends the hostname to the name of the log files.
166  ;appendhostname = yes
167  ;
168 +; This determines whether or not we log queue events to a file (defaults to yes).
169 +;queue_log = no
170 +;
171 +; This determines whether or not we log generic events to a file (defaults to yes).
172 +;event_log = no
173 +;
174  ;
175  ; For each file, specify what to log.
176  ;