ovs-appctl: Print command arguments for "help".
[sliver-openvswitch.git] / lib / vlog.c
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <config.h>
18 #include "vlog.h"
19 #include <assert.h>
20 #include <ctype.h>
21 #include <errno.h>
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <sys/types.h>
26 #include <syslog.h>
27 #include <time.h>
28 #include <unistd.h>
29 #include "dirs.h"
30 #include "dynamic-string.h"
31 #include "sat-math.h"
32 #include "svec.h"
33 #include "timeval.h"
34 #include "unixctl.h"
35 #include "util.h"
36
37 VLOG_DEFINE_THIS_MODULE(vlog);
38
39 /* Name for each logging level. */
40 static const char *level_names[VLL_N_LEVELS] = {
41 #define VLOG_LEVEL(NAME, SYSLOG_LEVEL) #NAME,
42     VLOG_LEVELS
43 #undef VLOG_LEVEL
44 };
45
46 /* Syslog value for each logging level. */
47 static int syslog_levels[VLL_N_LEVELS] = {
48 #define VLOG_LEVEL(NAME, SYSLOG_LEVEL) SYSLOG_LEVEL,
49     VLOG_LEVELS
50 #undef VLOG_LEVEL
51 };
52
53 /* The log modules. */
54 #if USE_LINKER_SECTIONS
55 extern struct vlog_module *__start_vlog_modules[];
56 extern struct vlog_module *__stop_vlog_modules[];
57 #define vlog_modules __start_vlog_modules
58 #define n_vlog_modules (__stop_vlog_modules - __start_vlog_modules)
59 #else
60 #define VLOG_MODULE VLOG_DEFINE_MODULE__
61 #include "vlog-modules.def"
62 #undef VLOG_MODULE
63
64 struct vlog_module *vlog_modules[] = {
65 #define VLOG_MODULE(NAME) &VLM_##NAME,
66 #include "vlog-modules.def"
67 #undef VLOG_MODULE
68 };
69 #define n_vlog_modules ARRAY_SIZE(vlog_modules)
70 #endif
71
72 /* Information about each facility. */
73 struct facility {
74     const char *name;           /* Name. */
75     char *pattern;              /* Current pattern. */
76     bool default_pattern;       /* Whether current pattern is the default. */
77 };
78 static struct facility facilities[VLF_N_FACILITIES] = {
79 #define VLOG_FACILITY(NAME, PATTERN) {#NAME, PATTERN, true},
80     VLOG_FACILITIES
81 #undef VLOG_FACILITY
82 };
83
84 /* Time at which vlog was initialized, in milliseconds. */
85 static long long int boot_time;
86
87 /* VLF_FILE configuration. */
88 static char *log_file_name;
89 static FILE *log_file;
90
91 /* vlog initialized? */
92 static bool vlog_inited;
93
94 static void format_log_message(const struct vlog_module *, enum vlog_level,
95                                enum vlog_facility, unsigned int msg_num,
96                                const char *message, va_list, struct ds *)
97     PRINTF_FORMAT(5, 0);
98
99 /* Searches the 'n_names' in 'names'.  Returns the index of a match for
100  * 'target', or 'n_names' if no name matches. */
101 static size_t
102 search_name_array(const char *target, const char **names, size_t n_names)
103 {
104     size_t i;
105
106     for (i = 0; i < n_names; i++) {
107         assert(names[i]);
108         if (!strcasecmp(names[i], target)) {
109             break;
110         }
111     }
112     return i;
113 }
114
115 /* Returns the name for logging level 'level'. */
116 const char *
117 vlog_get_level_name(enum vlog_level level)
118 {
119     assert(level < VLL_N_LEVELS);
120     return level_names[level];
121 }
122
123 /* Returns the logging level with the given 'name', or VLL_N_LEVELS if 'name'
124  * is not the name of a logging level. */
125 enum vlog_level
126 vlog_get_level_val(const char *name)
127 {
128     return search_name_array(name, level_names, ARRAY_SIZE(level_names));
129 }
130
131 /* Returns the name for logging facility 'facility'. */
132 const char *
133 vlog_get_facility_name(enum vlog_facility facility)
134 {
135     assert(facility < VLF_N_FACILITIES);
136     return facilities[facility].name;
137 }
138
139 /* Returns the logging facility named 'name', or VLF_N_FACILITIES if 'name' is
140  * not the name of a logging facility. */
141 enum vlog_facility
142 vlog_get_facility_val(const char *name)
143 {
144     size_t i;
145
146     for (i = 0; i < VLF_N_FACILITIES; i++) {
147         if (!strcasecmp(facilities[i].name, name)) {
148             break;
149         }
150     }
151     return i;
152 }
153
154 /* Returns the name for logging module 'module'. */
155 const char *
156 vlog_get_module_name(const struct vlog_module *module)
157 {
158     return module->name;
159 }
160
161 /* Returns the logging module named 'name', or NULL if 'name' is not the name
162  * of a logging module. */
163 struct vlog_module *
164 vlog_module_from_name(const char *name)
165 {
166     struct vlog_module **mp;
167
168     for (mp = vlog_modules; mp < &vlog_modules[n_vlog_modules]; mp++) {
169         if (!strcasecmp(name, (*mp)->name)) {
170             return *mp;
171         }
172     }
173     return NULL;
174 }
175
176 /* Returns the current logging level for the given 'module' and 'facility'. */
177 enum vlog_level
178 vlog_get_level(const struct vlog_module *module, enum vlog_facility facility)
179 {
180     assert(facility < VLF_N_FACILITIES);
181     return module->levels[facility];
182 }
183
184 static void
185 update_min_level(struct vlog_module *module)
186 {
187     enum vlog_facility facility;
188
189     module->min_level = VLL_OFF;
190     for (facility = 0; facility < VLF_N_FACILITIES; facility++) {
191         if (log_file || facility != VLF_FILE) {
192             enum vlog_level level = module->levels[facility];
193             if (level > module->min_level) {
194                 module->min_level = level;
195             }
196         }
197     }
198 }
199
200 static void
201 set_facility_level(enum vlog_facility facility, struct vlog_module *module,
202                    enum vlog_level level)
203 {
204     assert(facility >= 0 && facility < VLF_N_FACILITIES);
205     assert(level < VLL_N_LEVELS);
206
207     if (!module) {
208         struct vlog_module **mp;
209
210         for (mp = vlog_modules; mp < &vlog_modules[n_vlog_modules]; mp++) {
211             (*mp)->levels[facility] = level;
212             update_min_level(*mp);
213         }
214     } else {
215         module->levels[facility] = level;
216         update_min_level(module);
217     }
218 }
219
220 /* Sets the logging level for the given 'module' and 'facility' to 'level'.  A
221  * null 'module' or a 'facility' of VLF_ANY_FACILITY is treated as a wildcard
222  * across all modules or facilities, respectively. */
223 void
224 vlog_set_levels(struct vlog_module *module, enum vlog_facility facility,
225                 enum vlog_level level)
226 {
227     assert(facility < VLF_N_FACILITIES || facility == VLF_ANY_FACILITY);
228     if (facility == VLF_ANY_FACILITY) {
229         for (facility = 0; facility < VLF_N_FACILITIES; facility++) {
230             set_facility_level(facility, module, level);
231         }
232     } else {
233         set_facility_level(facility, module, level);
234     }
235 }
236
237 static void
238 do_set_pattern(enum vlog_facility facility, const char *pattern)
239 {
240     struct facility *f = &facilities[facility];
241     if (!f->default_pattern) {
242         free(f->pattern);
243     } else {
244         f->default_pattern = false;
245     }
246     f->pattern = xstrdup(pattern);
247 }
248
249 /* Sets the pattern for the given 'facility' to 'pattern'. */
250 void
251 vlog_set_pattern(enum vlog_facility facility, const char *pattern)
252 {
253     assert(facility < VLF_N_FACILITIES || facility == VLF_ANY_FACILITY);
254     if (facility == VLF_ANY_FACILITY) {
255         for (facility = 0; facility < VLF_N_FACILITIES; facility++) {
256             do_set_pattern(facility, pattern);
257         }
258     } else {
259         do_set_pattern(facility, pattern);
260     }
261 }
262
263 /* Returns the name of the log file used by VLF_FILE, or a null pointer if no
264  * log file has been set.  (A non-null return value does not assert that the
265  * named log file is in use: if vlog_set_log_file() or vlog_reopen_log_file()
266  * fails, it still sets the log file name.) */
267 const char *
268 vlog_get_log_file(void)
269 {
270     return log_file_name;
271 }
272
273 /* Sets the name of the log file used by VLF_FILE to 'file_name', or to the
274  * default file name if 'file_name' is null.  Returns 0 if successful,
275  * otherwise a positive errno value. */
276 int
277 vlog_set_log_file(const char *file_name)
278 {
279     char *old_log_file_name;
280     struct vlog_module **mp;
281     int error;
282
283     /* Close old log file. */
284     if (log_file) {
285         VLOG_INFO("closing log file");
286         fclose(log_file);
287         log_file = NULL;
288     }
289
290     /* Update log file name and free old name.  The ordering is important
291      * because 'file_name' might be 'log_file_name' or some suffix of it. */
292     old_log_file_name = log_file_name;
293     log_file_name = (file_name
294                      ? xstrdup(file_name)
295                      : xasprintf("%s/%s.log", ovs_logdir(), program_name));
296     free(old_log_file_name);
297     file_name = NULL;           /* Might have been freed. */
298
299     /* Open new log file and update min_levels[] to reflect whether we actually
300      * have a log_file. */
301     log_file = fopen(log_file_name, "a");
302     for (mp = vlog_modules; mp < &vlog_modules[n_vlog_modules]; mp++) {
303         update_min_level(*mp);
304     }
305
306     /* Log success or failure. */
307     if (!log_file) {
308         VLOG_WARN("failed to open %s for logging: %s",
309                   log_file_name, strerror(errno));
310         error = errno;
311     } else {
312         VLOG_INFO("opened log file %s", log_file_name);
313         error = 0;
314     }
315
316     return error;
317 }
318
319 /* Closes and then attempts to re-open the current log file.  (This is useful
320  * just after log rotation, to ensure that the new log file starts being used.)
321  * Returns 0 if successful, otherwise a positive errno value. */
322 int
323 vlog_reopen_log_file(void)
324 {
325     return log_file_name ? vlog_set_log_file(log_file_name) : 0;
326 }
327
328 /* Set debugging levels:
329  *
330  *  mod[:facility[:level]] mod2[:facility[:level]] ...
331  *
332  * Return null if successful, otherwise an error message that the caller must
333  * free().
334  */
335 char *
336 vlog_set_levels_from_string(const char *s_)
337 {
338     char *save_ptr = NULL;
339     char *s = xstrdup(s_);
340     char *module, *facility;
341
342     for (module = strtok_r(s, ": \t", &save_ptr); module != NULL;
343          module = strtok_r(NULL, ": \t", &save_ptr)) {
344         struct vlog_module *e_module;
345         enum vlog_facility e_facility;
346
347         facility = strtok_r(NULL, ":", &save_ptr);
348
349         if (!facility || !strcasecmp(facility, "ANY")) {
350             e_facility = VLF_ANY_FACILITY;
351         } else {
352             e_facility = vlog_get_facility_val(facility);
353             if (e_facility >= VLF_N_FACILITIES) {
354                 char *msg = xasprintf("unknown facility \"%s\"", facility);
355                 free(s);
356                 return msg;
357             }
358         }
359
360         if (!strcasecmp(module, "PATTERN")) {
361             vlog_set_pattern(e_facility, save_ptr);
362             break;
363         } else {
364             char *level;
365             enum vlog_level e_level;
366
367             if (!strcasecmp(module, "ANY")) {
368                 e_module = NULL;
369             } else {
370                 e_module = vlog_module_from_name(module);
371                 if (!e_module) {
372                     char *msg = xasprintf("unknown module \"%s\"", module);
373                     free(s);
374                     return msg;
375                 }
376             }
377
378             level = strtok_r(NULL, ":", &save_ptr);
379             e_level = level ? vlog_get_level_val(level) : VLL_DBG;
380             if (e_level >= VLL_N_LEVELS) {
381                 char *msg = xasprintf("unknown level \"%s\"", level);
382                 free(s);
383                 return msg;
384             }
385
386             vlog_set_levels(e_module, e_facility, e_level);
387         }
388     }
389     free(s);
390     return NULL;
391 }
392
393 /* If 'arg' is null, configure maximum verbosity.  Otherwise, sets
394  * configuration according to 'arg' (see vlog_set_levels_from_string()). */
395 void
396 vlog_set_verbosity(const char *arg)
397 {
398     if (arg) {
399         char *msg = vlog_set_levels_from_string(arg);
400         if (msg) {
401             ovs_fatal(0, "processing \"%s\": %s", arg, msg);
402         }
403     } else {
404         vlog_set_levels(NULL, VLF_ANY_FACILITY, VLL_DBG);
405     }
406 }
407
408 static void
409 vlog_unixctl_set(struct unixctl_conn *conn,
410                  const char *args, void *aux OVS_UNUSED)
411 {
412     char *msg = vlog_set_levels_from_string(args);
413     unixctl_command_reply(conn, msg ? 501 : 202, msg);
414     free(msg);
415 }
416
417 static void
418 vlog_unixctl_list(struct unixctl_conn *conn,
419                   const char *args OVS_UNUSED, void *aux OVS_UNUSED)
420 {
421     char *msg = vlog_get_levels();
422     unixctl_command_reply(conn, 200, msg);
423     free(msg);
424 }
425
426 static void
427 vlog_unixctl_reopen(struct unixctl_conn *conn,
428                     const char *args OVS_UNUSED, void *aux OVS_UNUSED)
429 {
430     if (log_file_name) {
431         int error = vlog_reopen_log_file();
432         if (error) {
433             unixctl_command_reply(conn, 503, strerror(errno));
434         } else {
435             unixctl_command_reply(conn, 202, NULL);
436         }
437     } else {
438         unixctl_command_reply(conn, 403, "Logging to file not configured");
439     }
440 }
441
442 /* Initializes the logging subsystem and registers its unixctl server
443  * commands. */
444 void
445 vlog_init(void)
446 {
447     time_t now;
448
449     if (vlog_inited) {
450         return;
451     }
452     vlog_inited = true;
453
454     openlog(program_name, LOG_NDELAY, LOG_DAEMON);
455
456     boot_time = time_msec();
457     now = time_wall();
458     if (now < 0) {
459         struct tm tm;
460         char s[128];
461
462         localtime_r(&now, &tm);
463         strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S %z", &tm);
464         VLOG_ERR("current time is negative: %s (%ld)", s, (long int) now);
465     }
466
467     unixctl_command_register("vlog/set",
468                    "{module[:facility[:level]] | PATTERN:facility:pattern}",
469                    vlog_unixctl_set, NULL);
470     unixctl_command_register("vlog/list", "", vlog_unixctl_list, NULL);
471     unixctl_command_register("vlog/reopen", "", vlog_unixctl_reopen, NULL);
472 }
473
474 /* Closes the logging subsystem. */
475 void
476 vlog_exit(void)
477 {
478     if (vlog_inited) {
479         closelog();
480         vlog_inited = false;
481     }
482 }
483
484 /* Print the current logging level for each module. */
485 char *
486 vlog_get_levels(void)
487 {
488     struct ds s = DS_EMPTY_INITIALIZER;
489     struct vlog_module **mp;
490     struct svec lines = SVEC_EMPTY_INITIALIZER;
491     char *line;
492     size_t i;
493
494     ds_put_format(&s, "                 console    syslog    file\n");
495     ds_put_format(&s, "                 -------    ------    ------\n");
496
497     for (mp = vlog_modules; mp < &vlog_modules[n_vlog_modules]; mp++) {
498         line = xasprintf("%-16s  %4s       %4s       %4s\n",
499            vlog_get_module_name(*mp),
500            vlog_get_level_name(vlog_get_level(*mp, VLF_CONSOLE)),
501            vlog_get_level_name(vlog_get_level(*mp, VLF_SYSLOG)),
502            vlog_get_level_name(vlog_get_level(*mp, VLF_FILE)));
503         svec_add_nocopy(&lines, line);
504     }
505
506     svec_sort(&lines);
507     SVEC_FOR_EACH (i, line, &lines) {
508         ds_put_cstr(&s, line);
509     }
510     svec_destroy(&lines);
511
512     return ds_cstr(&s);
513 }
514
515 /* Returns true if a log message emitted for the given 'module' and 'level'
516  * would cause some log output, false if that module and level are completely
517  * disabled. */
518 bool
519 vlog_is_enabled(const struct vlog_module *module, enum vlog_level level)
520 {
521     return module->min_level >= level;
522 }
523
524 static const char *
525 fetch_braces(const char *p, const char *def, char *out, size_t out_size)
526 {
527     if (*p == '{') {
528         size_t n = strcspn(p + 1, "}");
529         size_t n_copy = MIN(n, out_size - 1);
530         memcpy(out, p + 1, n_copy);
531         out[n_copy] = '\0';
532         p += n + 2;
533     } else {
534         ovs_strlcpy(out, def, out_size);
535     }
536     return p;
537 }
538
539 static void
540 format_log_message(const struct vlog_module *module, enum vlog_level level,
541                    enum vlog_facility facility, unsigned int msg_num,
542                    const char *message, va_list args_, struct ds *s)
543 {
544     char tmp[128];
545     va_list args;
546     const char *p;
547
548     ds_clear(s);
549     for (p = facilities[facility].pattern; *p != '\0'; ) {
550         enum { LEFT, RIGHT } justify = RIGHT;
551         int pad = '0';
552         size_t length, field, used;
553
554         if (*p != '%') {
555             ds_put_char(s, *p++);
556             continue;
557         }
558
559         p++;
560         if (*p == '-') {
561             justify = LEFT;
562             p++;
563         }
564         if (*p == '0') {
565             pad = '0';
566             p++;
567         }
568         field = 0;
569         while (isdigit((unsigned char)*p)) {
570             field = (field * 10) + (*p - '0');
571             p++;
572         }
573
574         length = s->length;
575         switch (*p++) {
576         case 'A':
577             ds_put_cstr(s, program_name);
578             break;
579         case 'c':
580             p = fetch_braces(p, "", tmp, sizeof tmp);
581             ds_put_cstr(s, vlog_get_module_name(module));
582             break;
583         case 'd':
584             p = fetch_braces(p, "%Y-%m-%d %H:%M:%S", tmp, sizeof tmp);
585             ds_put_strftime(s, tmp, NULL);
586             break;
587         case 'm':
588             /* Format user-supplied log message and trim trailing new-lines. */
589             length = s->length;
590             va_copy(args, args_);
591             ds_put_format_valist(s, message, args);
592             va_end(args);
593             while (s->length > length && s->string[s->length - 1] == '\n') {
594                 s->length--;
595             }
596             break;
597         case 'N':
598             ds_put_format(s, "%u", msg_num);
599             break;
600         case 'n':
601             ds_put_char(s, '\n');
602             break;
603         case 'p':
604             ds_put_cstr(s, vlog_get_level_name(level));
605             break;
606         case 'P':
607             ds_put_format(s, "%ld", (long int) getpid());
608             break;
609         case 'r':
610             ds_put_format(s, "%lld", time_msec() - boot_time);
611             break;
612         default:
613             ds_put_char(s, p[-1]);
614             break;
615         }
616         used = s->length - length;
617         if (used < field) {
618             size_t n_pad = field - used;
619             if (justify == RIGHT) {
620                 ds_put_uninit(s, n_pad);
621                 memmove(&s->string[length + n_pad], &s->string[length], used);
622                 memset(&s->string[length], pad, n_pad);
623             } else {
624                 ds_put_char_multiple(s, pad, n_pad);
625             }
626         }
627     }
628 }
629
630 /* Writes 'message' to the log at the given 'level' and as coming from the
631  * given 'module'.
632  *
633  * Guaranteed to preserve errno. */
634 void
635 vlog_valist(const struct vlog_module *module, enum vlog_level level,
636             const char *message, va_list args)
637 {
638     bool log_to_console = module->levels[VLF_CONSOLE] >= level;
639     bool log_to_syslog = module->levels[VLF_SYSLOG] >= level;
640     bool log_to_file = module->levels[VLF_FILE] >= level && log_file;
641     if (log_to_console || log_to_syslog || log_to_file) {
642         int save_errno = errno;
643         static unsigned int msg_num;
644         struct ds s;
645
646         vlog_init();
647
648         ds_init(&s);
649         ds_reserve(&s, 1024);
650         msg_num++;
651
652         if (log_to_console) {
653             format_log_message(module, level, VLF_CONSOLE, msg_num,
654                                message, args, &s);
655             ds_put_char(&s, '\n');
656             fputs(ds_cstr(&s), stderr);
657         }
658
659         if (log_to_syslog) {
660             int syslog_level = syslog_levels[level];
661             char *save_ptr = NULL;
662             char *line;
663
664             format_log_message(module, level, VLF_SYSLOG, msg_num,
665                                message, args, &s);
666             for (line = strtok_r(s.string, "\n", &save_ptr); line;
667                  line = strtok_r(NULL, "\n", &save_ptr)) {
668                 syslog(syslog_level, "%s", line);
669             }
670         }
671
672         if (log_to_file) {
673             format_log_message(module, level, VLF_FILE, msg_num,
674                                message, args, &s);
675             ds_put_char(&s, '\n');
676             fputs(ds_cstr(&s), log_file);
677             fflush(log_file);
678         }
679
680         ds_destroy(&s);
681         errno = save_errno;
682     }
683 }
684
685 void
686 vlog(const struct vlog_module *module, enum vlog_level level,
687      const char *message, ...)
688 {
689     va_list args;
690
691     va_start(args, message);
692     vlog_valist(module, level, message, args);
693     va_end(args);
694 }
695
696 void
697 vlog_fatal_valist(const struct vlog_module *module_,
698                   const char *message, va_list args)
699 {
700     struct vlog_module *module = (struct vlog_module *) module_;
701
702     /* Don't log this message to the console to avoid redundancy with the
703      * message written by the later ovs_fatal_valist(). */
704     module->levels[VLF_CONSOLE] = VLL_OFF;
705
706     vlog_valist(module, VLL_EMER, message, args);
707     ovs_fatal_valist(0, message, args);
708 }
709
710 void
711 vlog_fatal(const struct vlog_module *module, const char *message, ...)
712 {
713     va_list args;
714
715     va_start(args, message);
716     vlog_fatal_valist(module, message, args);
717     va_end(args);
718 }
719
720 bool
721 vlog_should_drop(const struct vlog_module *module, enum vlog_level level,
722                  struct vlog_rate_limit *rl)
723 {
724     if (!vlog_is_enabled(module, level)) {
725         return true;
726     }
727
728     if (rl->tokens < VLOG_MSG_TOKENS) {
729         time_t now = time_now();
730         if (rl->last_fill > now) {
731             /* Last filled in the future?  Time must have gone backward, or
732              * 'rl' has not been used before. */
733             rl->tokens = rl->burst;
734         } else if (rl->last_fill < now) {
735             unsigned int add = sat_mul(rl->rate, now - rl->last_fill);
736             unsigned int tokens = sat_add(rl->tokens, add);
737             rl->tokens = MIN(tokens, rl->burst);
738             rl->last_fill = now;
739         }
740         if (rl->tokens < VLOG_MSG_TOKENS) {
741             if (!rl->n_dropped) {
742                 rl->first_dropped = now;
743             }
744             rl->last_dropped = now;
745             rl->n_dropped++;
746             return true;
747         }
748     }
749     rl->tokens -= VLOG_MSG_TOKENS;
750
751     if (rl->n_dropped) {
752         time_t now = time_now();
753         unsigned int first_dropped_elapsed = now - rl->first_dropped;
754         unsigned int last_dropped_elapsed = now - rl->last_dropped;
755
756         vlog(module, level,
757              "Dropped %u log messages in last %u seconds (most recently, "
758              "%u seconds ago) due to excessive rate",
759              rl->n_dropped, first_dropped_elapsed, last_dropped_elapsed);
760
761         rl->n_dropped = 0;
762     }
763     return false;
764 }
765
766 void
767 vlog_rate_limit(const struct vlog_module *module, enum vlog_level level,
768                 struct vlog_rate_limit *rl, const char *message, ...)
769 {
770     if (!vlog_should_drop(module, level, rl)) {
771         va_list args;
772
773         va_start(args, message);
774         vlog_valist(module, level, message, args);
775         va_end(args);
776     }
777 }
778
779 void
780 vlog_usage(void)
781 {
782     printf("\nLogging options:\n"
783            "  -v, --verbose=MODULE[:FACILITY[:LEVEL]]  set logging levels\n"
784            "  -v, --verbose           set maximum verbosity level\n"
785            "  --log-file[=FILE]       enable logging to specified FILE\n"
786            "                          (default: %s/%s.log)\n",
787            ovs_logdir(), program_name);
788 }