open62541 1.4.15
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
29#define UA_LOGCATEGORIES 10
30
43
44typedef struct UA_Logger {
45 /* Log a message. The message string and following varargs are formatted
46 * according to the rules of the printf command. Use the convenience macros
47 * below that take the minimum log level defined in ua_config.h into
48 * account. */
49 void (*log)(void *logContext, UA_LogLevel level, UA_LogCategory category,
50 const char *msg, va_list args);
51
52 void *context; /* Logger state */
53
54 void (*clear)(struct UA_Logger *logger); /* Clean up the logger plugin */
56
57static UA_FORMAT(3,4) void
58UA_LOG_TRACE(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
59#if UA_LOGLEVEL <= 100
60 if(!logger || !logger->log)
61 return;
62 va_list args; va_start(args, msg);
63 logger->log(logger->context, UA_LOGLEVEL_TRACE, category, msg, args);
65#else
66 (void) logger;
67 (void) category;
68 (void) msg;
69#endif
70}
71
72static UA_FORMAT(3,4) void
73UA_LOG_DEBUG(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
74#if UA_LOGLEVEL <= 200
75 if(!logger || !logger->log)
76 return;
77 va_list args; va_start(args, msg);
78 logger->log(logger->context, UA_LOGLEVEL_DEBUG, category, msg, args);
79 va_end(args);
80#else
81 (void) logger;
82 (void) category;
83 (void) msg;
84#endif
85}
86
87static UA_FORMAT(3,4) void
88UA_LOG_INFO(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
89#if UA_LOGLEVEL <= 300
90 if(!logger || !logger->log)
91 return;
92 va_list args; va_start(args, msg);
93 logger->log(logger->context, UA_LOGLEVEL_INFO, category, msg, args);
94 va_end(args);
95#else
96 (void) logger;
97 (void) category;
98 (void) msg;
99#endif
100}
101
102static UA_FORMAT(3,4) void
103UA_LOG_WARNING(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
104#if UA_LOGLEVEL <= 400
105 if(!logger || !logger->log)
106 return;
107 va_list args; va_start(args, msg);
108 logger->log(logger->context, UA_LOGLEVEL_WARNING, category, msg, args);
109 va_end(args);
110#else
111 (void) logger;
112 (void) category;
113 (void) msg;
114#endif
115}
116
117static UA_FORMAT(3,4) void
118UA_LOG_ERROR(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
119#if UA_LOGLEVEL <= 500
120 if(!logger || !logger->log)
121 return;
122 va_list args; va_start(args, msg);
123 logger->log(logger->context, UA_LOGLEVEL_ERROR, category, msg, args);
124 va_end(args);
125#else
126 (void) logger;
127 (void) category;
128 (void) msg;
129#endif
130}
131
132static UA_FORMAT(3,4) void
133UA_LOG_FATAL(const UA_Logger *logger, UA_LogCategory category, const char *msg, ...) {
134#if UA_LOGLEVEL <= 600
135 if(!logger || !logger->log)
136 return;
137 va_list args; va_start(args, msg);
138 logger->log(logger->context, UA_LOGLEVEL_FATAL, category, msg, args);
139 va_end(args);
140#else
141 (void) logger;
142 (void) category;
143 (void) msg;
144#endif
145}
146
148
149#endif /* UA_PLUGIN_LOG_H_ */
#define UA_FORMAT(X, Y)
Definition config.h:454
#define _UA_BEGIN_DECLS
#undef UA_DEBUG_DUMP_PKGS
Definition config.h:100
#define _UA_END_DECLS
Definition config.h:107
static UA_LogCategory const char va_list args
Definition log.h:62
va_end(args)
static UA_LogCategory category
Definition log.h:58
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:31
@ UA_LOGCATEGORY_NETWORK
Definition log.h:32
@ UA_LOGCATEGORY_USERLAND
Definition log.h:37
@ UA_LOGCATEGORY_PUBSUB
Definition log.h:40
@ UA_LOGCATEGORY_SERVER
Definition log.h:35
@ UA_LOGCATEGORY_SESSION
Definition log.h:34
@ UA_LOGCATEGORY_EVENTLOOP
Definition log.h:39
@ UA_LOGCATEGORY_SECURITYPOLICY
Definition log.h:38
@ UA_LOGCATEGORY_DISCOVERY
Definition log.h:41
@ UA_LOGCATEGORY_CLIENT
Definition log.h:36
@ UA_LOGCATEGORY_SECURECHANNEL
Definition log.h:33
static UA_LogCategory const char * msg
Definition log.h:58
void(* log)(void *logContext, UA_LogLevel level, UA_LogCategory category, const char *msg, va_list args)
Definition log.h:49
void * context
Definition log.h:52
void(* clear)(struct UA_Logger *logger)
Definition log.h:54