src/ucx/logging.h

Fri, 05 Jul 2019 15:07:43 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 05 Jul 2019 15:07:43 +0200
branch
feature/array
changeset 339
ae368664625f
parent 295
7fc65395188e
child 376
028039652b86
permissions
-rw-r--r--

fixes doxygen doc

103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
1 /*
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
3 *
259
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
4 * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
103
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
5 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
6 * Redistribution and use in source and binary forms, with or without
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
7 * modification, are permitted provided that the following conditions are met:
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
8 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
10 * notice, this list of conditions and the following disclaimer.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
11 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
14 * documentation and/or other materials provided with the distribution.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
15 *
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
08018864fb91 added license and copyright notice to all files
Mike Becker <universe@uap-core.de>
parents: 83
diff changeset
27 */
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
28 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
29 * Logging API.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
30 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
31 * @file logging.h
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
32 * @author Mike Becker, Olaf Wintermann
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
33 */
120
8170f658f017 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
34 #ifndef UCX_LOGGING_H
8170f658f017 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
35 #define UCX_LOGGING_H
57
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
36
259
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
37 #include "ucx.h"
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
38 #include "map.h"
2f5dea574a75 modules documentation
Mike Becker <universe@uap-core.de>
parents: 251
diff changeset
39 #include "string.h"
57
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
40 #include <stdio.h>
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
41
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
42 #ifdef __cplusplus
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
43 extern "C" {
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
44 #endif
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
45
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
46 /* leave enough space for custom log levels */
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
47
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
48 /** Log level for error messages. */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
49 #define UCX_LOGGER_ERROR 0x00
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
50
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
51 /** Log level for warning messages. */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
52 #define UCX_LOGGER_WARN 0x10
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
53
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
54 /** Log level for information messages. */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
55 #define UCX_LOGGER_INFO 0x20
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
56
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
57 /** Log level for debug messages. */
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
58 #define UCX_LOGGER_DEBUG 0x30
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
59
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
60 /** Log level for trace messages. */
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
61 #define UCX_LOGGER_TRACE 0x40
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
62
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
63 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
64 * Output flag for the log level.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
65 * If this flag is set, the log message will contain the log level.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
66 * @see UcxLogger.mask
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
67 */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
68 #define UCX_LOGGER_LEVEL 0x01
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
69
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
70 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
71 * Output flag for the timestmap.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
72 * If this flag is set, the log message will contain the timestmap.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
73 * @see UcxLogger.mask
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
74 */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
75 #define UCX_LOGGER_TIMESTAMP 0x02
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
76
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
77 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
78 * Output flag for the source.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
79 * If this flag is set, the log message will contain the source file and line
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
80 * number.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
81 * @see UcxLogger.mask
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
82 */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
83 #define UCX_LOGGER_SOURCE 0x04
57
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
84
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
85 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
86 * The UCX Logger object.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
87 */
57
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
88 typedef struct {
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
89 /** The stream this logger writes its messages to.*/
83
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
90 void *stream;
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
91
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
92 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
93 * The write function that shall be used.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
94 * For standard file or stdout loggers this might be standard fwrite
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
95 * (default).
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
96 */
82
6068d965328b logger can now log timestamps
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
97 write_func writer;
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
98
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
99 /**
170
5fbb9efebe4a improved logger tests
Mike Becker <universe@uap-core.de>
parents: 146
diff changeset
100 * The date format for timestamp outputs including the delimiter
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
101 * (default: <code>"%F %T %z "</code>).
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
102 * @see UCX_LOGGER_TIMESTAMP
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
103 */
82
6068d965328b logger can now log timestamps
Mike Becker <universe@uap-core.de>
parents: 81
diff changeset
104 char *dateformat;
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
105
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
106 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
107 * The level, this logger operates on.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
108 * If a log command is issued, the message will only be logged, if the log
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
109 * level of the message is less or equal than the log level of the logger.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
110 */
57
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
111 unsigned int level;
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
112
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
113 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
114 * A configuration mask for automatic output.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
115 * For each flag that is set, the logger automatically outputs some extra
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
116 * information like the timestamp or the source file and line number.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
117 * See the documentation for the flags for details.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
118 */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
119 unsigned int mask;
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
120
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
121 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
122 * A map of valid log levels for this logger.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
123 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
124 * The keys represent all valid log levels and the values provide string
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
125 * representations, that are used, if the UCX_LOGGER_LEVEL flag is set.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
126 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
127 * The exact data types are <code>unsigned int</code> for the key and
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
128 * <code>const char*</code> for the value.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
129 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
130 * @see UCX_LOGGER_LEVEL
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
131 */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
132 UcxMap* levels;
57
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
133 } UcxLogger;
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
134
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
135 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
136 * Creates a new logger.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
137 * @param stream the stream, which the logger shall write to
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
138 * @param level the level on which the logger shall operate
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
139 * @param mask configuration mask (cf. UcxLogger.mask)
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
140 * @return a new logger object
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
141 */
83
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
142 UcxLogger *ucx_logger_new(void *stream, unsigned int level, unsigned int mask);
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
143
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
144 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
145 * Destroys the logger.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
146 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
147 * The map containing the valid log levels is also automatically destroyed.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
148 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
149 * @param logger the logger to destroy
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
150 */
80
0125e4089f88 Fixed map tests + added some formatting options to logger
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
151 void ucx_logger_free(UcxLogger* logger);
57
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
152
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
153 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
154 * Internal log function - use macros instead.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
155 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
156 * This function uses the <code>format</code> and variadic arguments for a
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
157 * printf()-style output of the log message.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
158 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
159 * Dependent on the UcxLogger.mask some information is prepended. The complete
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
160 * format is:
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
161 *
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
162 * <code>[LEVEL] [TIMESTAMP] [SOURCEFILE]:[LINENO] message</code>
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
163 *
138
7800811078b8 documented map.h + changed return value of ucx_map_iter_next()
Mike Becker <universe@uap-core.de>
parents: 129
diff changeset
164 * <b>Attention:</b> the message (including automatically generated information)
171
49cebb8eceff logger: removed unnecessary boundary checks and limited string parts so they always respect buffer lengths
Mike Becker <universe@uap-core.de>
parents: 170
diff changeset
165 * is limited to 4096 characters. The level description is limited to
49cebb8eceff logger: removed unnecessary boundary checks and limited string parts so they always respect buffer lengths
Mike Becker <universe@uap-core.de>
parents: 170
diff changeset
166 * 256 characters and the timestamp string is limited to 128 characters.
138
7800811078b8 documented map.h + changed return value of ucx_map_iter_next()
Mike Becker <universe@uap-core.de>
parents: 129
diff changeset
167 *
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
168 * @param logger the logger to use
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
169 * @param level the level to log on
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
170 * @param file information about the source file
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
171 * @param line information about the source line number
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
172 * @param format format string
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
173 * @param ... arguments
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
174 * @see ucx_logger_log()
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
175 */
81
86a23238d8a1 changed logger to behave more like printf + added possibility to specify write function
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
176 void ucx_logger_logf(UcxLogger *logger, unsigned int level, const char* file,
86a23238d8a1 changed logger to behave more like printf + added possibility to specify write function
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
177 const unsigned int line, const char* format, ...);
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
178
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
179 /**
295
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
180 * Registers a custom log level.
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
181 * @param logger the logger
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
182 * @param level the log level as unsigned integer
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
183 * @param name a string literal describing the level
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
184 */
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
185 #define ucx_logger_register_level(logger, level, name) {\
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
186 unsigned int l; \
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
187 l = level; \
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
188 ucx_map_int_put(logger->levels, l, (void*) "[" name "]"); \
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
189 } while (0);
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
190
7fc65395188e documents (and fixes!) the UcxLogger
Mike Becker <universe@uap-core.de>
parents: 259
diff changeset
191 /**
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
192 * Logs a message at the specified level.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
193 * @param logger the logger to use
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
194 * @param level the level to log the message on
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
195 * @param ... format string and arguments
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
196 * @see ucx_logger_logf()
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
197 */
83
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
198 #define ucx_logger_log(logger, level, ...) \
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
199 ucx_logger_logf(logger, level, __FILE__, __LINE__, __VA_ARGS__)
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
200
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
201 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
202 * Shortcut for logging an error message.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
203 * @param logger the logger to use
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
204 * @param ... format string and arguments
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
205 * @see ucx_logger_logf()
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
206 */
83
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
207 #define ucx_logger_error(logger, ...) \
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
208 ucx_logger_log(logger, UCX_LOGGER_ERROR, __VA_ARGS__)
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
209
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
210 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
211 * Shortcut for logging an information message.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
212 * @param logger the logger to use
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
213 * @param ... format string and arguments
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
214 * @see ucx_logger_logf()
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
215 */
83
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
216 #define ucx_logger_info(logger, ...) \
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
217 ucx_logger_log(logger, UCX_LOGGER_INFO, __VA_ARGS__)
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
218
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
219 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
220 * Shortcut for logging a warning message.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
221 * @param logger the logger to use
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
222 * @param ... format string and arguments
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
223 * @see ucx_logger_logf()
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
224 */
83
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
225 #define ucx_logger_warn(logger, ...) \
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
226 ucx_logger_log(logger, UCX_LOGGER_WARN, __VA_ARGS__)
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
227
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
228 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
229 * Shortcut for logging a debug message.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
230 * @param logger the logger to use
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
231 * @param ... format string and arguments
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
232 * @see ucx_logger_logf()
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
233 */
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
234 #define ucx_logger_debug(logger, ...) \
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
235 ucx_logger_log(logger, UCX_LOGGER_DEBUG, __VA_ARGS__)
146
aa376dba1ba8 fixed documentation for netbeans parser + added sstrprefix() and sstrsuffix()
Mike Becker <universe@uap-core.de>
parents: 138
diff changeset
236
129
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
237 /**
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
238 * Shortcut for logging a trace message.
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
239 * @param logger the logger to use
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
240 * @param ... format string and arguments
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
241 * @see ucx_logger_logf()
61edec666928 documentation for UcxLogger
Mike Becker <universe@uap-core.de>
parents: 120
diff changeset
242 */
83
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
243 #define ucx_logger_trace(logger, ...) \
3b552d7a9610 modified code to compile with -pedantic
Mike Becker <universe@uap-core.de>
parents: 82
diff changeset
244 ucx_logger_log(logger, UCX_LOGGER_TRACE, __VA_ARGS__)
57
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
245
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
246 #ifdef __cplusplus
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
247 }
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
248 #endif
e18157c52985 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
249
120
8170f658f017 some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 103
diff changeset
250 #endif /* UCX_LOGGING_H */

mercurial