~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to lib/vlog.h

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#ifndef VLOG_H
18
18
#define VLOG_H 1
19
19
 
 
20
/* Logging.
 
21
 *
 
22
 *
 
23
 * Thread-safety
 
24
 * =============
 
25
 *
 
26
 * Fully thread safe.
 
27
 */
 
28
 
20
29
#include <limits.h>
21
30
#include <stdarg.h>
22
31
#include <stdbool.h>
23
32
#include <time.h>
24
33
#include "compiler.h"
 
34
#include "ovs-thread.h"
25
35
#include "sat-math.h"
26
36
#include "token-bucket.h"
27
37
#include "util.h"
52
62
 
53
63
/* Facilities that we can log to. */
54
64
#define VLOG_FACILITIES                                                 \
55
 
    VLOG_FACILITY(SYSLOG, "%05N|%c%T|%p|%m")                            \
 
65
    VLOG_FACILITY(SYSLOG, "ovs|%05N|%c%T|%p|%m")                            \
56
66
    VLOG_FACILITY(CONSOLE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m")    \
57
67
    VLOG_FACILITY(FILE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m")
58
68
enum vlog_facility {
78
88
#if USE_LINKER_SECTIONS
79
89
#define VLOG_DEFINE_MODULE(MODULE)                                      \
80
90
        VLOG_DEFINE_MODULE__(MODULE)                                    \
81
 
        extern struct vlog_module *vlog_module_ptr_##MODULE;            \
82
 
        struct vlog_module *vlog_module_ptr_##MODULE                    \
 
91
        extern struct vlog_module *const vlog_module_ptr_##MODULE;      \
 
92
        struct vlog_module *const vlog_module_ptr_##MODULE              \
83
93
            __attribute__((section("vlog_modules"))) = &VLM_##MODULE
84
94
#else
85
95
#define VLOG_DEFINE_MODULE(MODULE) extern struct vlog_module VLM_##MODULE
94
104
    time_t first_dropped;       /* Time first message was dropped. */
95
105
    time_t last_dropped;        /* Time of most recent message drop. */
96
106
    unsigned int n_dropped;     /* Number of messages dropped. */
 
107
    struct ovs_mutex mutex;     /* Mutual exclusion for rate limit. */
97
108
};
98
109
 
99
110
/* Number of tokens to emit a message.  We add 'rate' tokens per millisecond,
108
119
            0,                              /* first_dropped */         \
109
120
            0,                              /* last_dropped */          \
110
121
            0,                              /* n_dropped */             \
 
122
            OVS_ADAPTIVE_MUTEX_INITIALIZER  /* mutex */                 \
111
123
        }
112
124
 
113
125
/* Configuring how each module logs messages. */
124
136
 
125
137
/* Configuring log facilities. */
126
138
void vlog_set_pattern(enum vlog_facility, const char *pattern);
127
 
const char *vlog_get_log_file(void);
128
139
int vlog_set_log_file(const char *file_name);
129
140
int vlog_reopen_log_file(void);
130
141
 
131
142
/* Initialization. */
132
143
void vlog_init(void);
133
 
void vlog_exit(void);
134
144
 
135
145
/* Functions for actual logging. */
136
146
void vlog(const struct vlog_module *, enum vlog_level, const char *format, ...)
230
240
            vlog_rate_limit(THIS_MODULE, level__, RL, __VA_ARGS__); \
231
241
        }                                                           \
232
242
    } while (0)
233
 
#define VLOG_ONCE(LEVEL, ...)                       \
234
 
    do {                                            \
235
 
        static bool already_logged;                 \
236
 
        if (!already_logged) {                      \
237
 
            already_logged = true;                  \
238
 
            vlog(THIS_MODULE, LEVEL, __VA_ARGS__);  \
239
 
        }                                           \
 
243
#define VLOG_ONCE(LEVEL, ...)                                           \
 
244
    do {                                                                \
 
245
        static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; \
 
246
        if (ovsthread_once_start(&once)) {                              \
 
247
            vlog(THIS_MODULE, LEVEL, __VA_ARGS__);                      \
 
248
            ovsthread_once_done(&once);                                 \
 
249
        }                                                               \
240
250
    } while (0)
241
251
 
242
252
#define VLOG_DEFINE_MODULE__(MODULE)                                    \