open62541 1.3.12
Open source implementation of OPC UA
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1/** This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 *
5 * Copyright 2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
6 * Copyright 2017 (c) Stefan Profanter, fortiss GmbH
7 */
8
9#ifndef UA_PLUGIN_LOG_H_
10#define UA_PLUGIN_LOG_H_
11
12#include <open62541/config.h>
13
14#include <stdarg.h>
15
17
18
19
28
38
39typedef struct {
40 /* Log a message. The message string and following varargs are formatted
41 * according to the rules of the printf command. Use the convenience macros
42 * below that take the minimum log level defined in ua_config.h into
43 * account. */
44 void (*log)(void *logContext, UA_LogLevel level, UA_LogCategory category,
45 const char *msg, va_list args);
46
47 void *context; /* Logger state */
48
49 void (*clear)(void *context); /* Clean up the logger plugin */
50} UA_Logger;
51
52static UA_FORMAT(3,4) void
53UA_LOG_TRACE(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
54#if UA_LOGLEVEL <= 100
55 if(!logger || !logger->log)
56 return;
57 va_list args; va_start(args, msg);
58 logger->log(logger->context, UA_LOGLEVEL_TRACE, category, msg, args);
60#else
61 (void) logger;
62 (void) category;
63 (void) msg;
64#endif
65}
66
67static UA_FORMAT(3,4) void
68UA_LOG_DEBUG(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
69#if UA_LOGLEVEL <= 200
70 if(!logger || !logger->log)
71 return;
72 va_list args; va_start(args, msg);
73 logger->log(logger->context, UA_LOGLEVEL_DEBUG, category, msg, args);
74 va_end(args);
75#else
76 (void) logger;
77 (void) category;
78 (void) msg;
79#endif
80}
81
82static UA_FORMAT(3,4) void
83UA_LOG_INFO(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
84#if UA_LOGLEVEL <= 300
85 if(!logger || !logger->log)
86 return;
87 va_list args; va_start(args, msg);
88 logger->log(logger->context, UA_LOGLEVEL_INFO, category, msg, args);
89 va_end(args);
90#else
91 (void) logger;
92 (void) category;
93 (void) msg;
94#endif
95}
96
97static UA_FORMAT(3,4) void
98UA_LOG_WARNING(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
99#if UA_LOGLEVEL <= 400
100 if(!logger || !logger->log)
101 return;
102 va_list args; va_start(args, msg);
103 logger->log(logger->context, UA_LOGLEVEL_WARNING, category, msg, args);
104 va_end(args);
105#else
106 (void) logger;
107 (void) category;
108 (void) msg;
109#endif
110}
111
112static UA_FORMAT(3,4) void
113UA_LOG_ERROR(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
114#if UA_LOGLEVEL <= 500
115 if(!logger || !logger->log)
116 return;
117 va_list args; va_start(args, msg);
118 logger->log(logger->context, UA_LOGLEVEL_ERROR, category, msg, args);
119 va_end(args);
120#else
121 (void) logger;
122 (void) category;
123 (void) msg;
124#endif
125}
126
127static UA_FORMAT(3,4) void
128UA_LOG_FATAL(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
129#if UA_LOGLEVEL <= 600
130 if(!logger || !logger->log)
131 return;
132 va_list args; va_start(args, msg);
133 logger->log(logger->context, UA_LOGLEVEL_FATAL, category, msg, args);
134 va_end(args);
135#else
136 (void) logger;
137 (void) category;
138 (void) msg;
139#endif
140}
141
143
144#endif /* UA_PLUGIN_LOG_H_ */
#define UA_FORMAT(X, Y)
#define _UA_BEGIN_DECLS
#undef UA_DEBUG_DUMP_PKGS
Definition config.h:89
#define _UA_END_DECLS
Definition config.h:96
static UA_LogCategory const char va_list args
Definition log.h:57
va_end(args)
logger log(logger->context, UA_LOGLEVEL_TRACE, category, msg, args)
static UA_LogCategory category
Definition log.h:53
va_start(args, msg)
UA_LogLevel
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition log.h:20
@ UA_LOGLEVEL_TRACE
Definition log.h:21
@ UA_LOGLEVEL_DEBUG
Definition log.h:22
@ UA_LOGLEVEL_INFO
Definition log.h:23
@ UA_LOGLEVEL_ERROR
Definition log.h:25
@ UA_LOGLEVEL_WARNING
Definition log.h:24
@ UA_LOGLEVEL_FATAL
Definition log.h:26
UA_LogCategory
Definition log.h:29
@ UA_LOGCATEGORY_NETWORK
Definition log.h:30
@ UA_LOGCATEGORY_USERLAND
Definition log.h:35
@ UA_LOGCATEGORY_SERVER
Definition log.h:33
@ UA_LOGCATEGORY_SESSION
Definition log.h:32
@ UA_LOGCATEGORY_SECURITYPOLICY
Definition log.h:36
@ UA_LOGCATEGORY_CLIENT
Definition log.h:34
@ UA_LOGCATEGORY_SECURECHANNEL
Definition log.h:31
static UA_LogCategory const char * msg
Definition log.h:53
void * context
Definition log.h:47