stumpless 2.2.0
Loading...
Searching...
No Matches
severity.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: Apache-2.0 */
2
3/*
4 * Copyright 2018-2024 Joel E. Anderson
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
26#ifndef __STUMPLESS_SEVERITY_H
27# define __STUMPLESS_SEVERITY_H
28
29# include <stumpless/config.h>
30# include <stumpless/generator.h>
31# include <stddef.h>
32
33# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
34# include <syslog.h>
35# endif
36
38# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
39# define STUMPLESS_SEVERITY_MASK( SEVERITY ) ( LOG_MASK( SEVERITY ) )
40# else
41# define STUMPLESS_SEVERITY_MASK( SEVERITY ) ( 1 << ( SEVERITY ) )
42# endif
43
45# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
46# define STUMPLESS_SEVERITY_MASK_UPTO( SEVERITY ) ( LOG_UPTO( SEVERITY ) )
47# else
48# define STUMPLESS_SEVERITY_MASK_UPTO( SEVERITY ) \
49( ( 1 << ( ( SEVERITY ) + 1 ) ) - 1 )
50# endif
51
57# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
58# define STUMPLESS_SEVERITY_EMERG_VALUE LOG_EMERG
59# else
60# define STUMPLESS_SEVERITY_EMERG_VALUE 0
61# endif
62
68# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
69# define STUMPLESS_SEVERITY_ALERT_VALUE LOG_ALERT
70# else
71# define STUMPLESS_SEVERITY_ALERT_VALUE 1
72# endif
73
79# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
80# define STUMPLESS_SEVERITY_CRIT_VALUE LOG_CRIT
81# else
82# define STUMPLESS_SEVERITY_CRIT_VALUE 2
83# endif
84
90# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
91# define STUMPLESS_SEVERITY_ERR_VALUE LOG_ERR
92# else
93# define STUMPLESS_SEVERITY_ERR_VALUE 3
94# endif
95
101# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
102# define STUMPLESS_SEVERITY_WARNING_VALUE LOG_WARNING
103# else
104# define STUMPLESS_SEVERITY_WARNING_VALUE 4
105# endif
106
112# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
113# define STUMPLESS_SEVERITY_NOTICE_VALUE LOG_NOTICE
114# else
115# define STUMPLESS_SEVERITY_NOTICE_VALUE 5
116# endif
117
123# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
124# define STUMPLESS_SEVERITY_INFO_VALUE LOG_INFO
125# else
126# define STUMPLESS_SEVERITY_INFO_VALUE 6
127# endif
128
134# ifdef STUMPLESS_SYSLOG_H_COMPATIBLE
135# define STUMPLESS_SEVERITY_DEBUG_VALUE LOG_DEBUG
136# else
137# define STUMPLESS_SEVERITY_DEBUG_VALUE 7
138# endif
139
146# define STUMPLESS_SEVERITY_TRACE_VALUE STUMPLESS_SEVERITY_DEBUG_VALUE
147
156# define STUMPLESS_FOREACH_SEVERITY( ACTION ) \
157 \
158ACTION( STUMPLESS_SEVERITY_EMERG, STUMPLESS_SEVERITY_EMERG_VALUE ) \
159 \
160ACTION( STUMPLESS_SEVERITY_ALERT, STUMPLESS_SEVERITY_ALERT_VALUE ) \
161 \
162ACTION( STUMPLESS_SEVERITY_CRIT, STUMPLESS_SEVERITY_CRIT_VALUE ) \
163 \
164ACTION( STUMPLESS_SEVERITY_ERR, STUMPLESS_SEVERITY_ERR_VALUE ) \
165 \
166ACTION( STUMPLESS_SEVERITY_WARNING, STUMPLESS_SEVERITY_WARNING_VALUE ) \
167 \
168ACTION( STUMPLESS_SEVERITY_NOTICE, STUMPLESS_SEVERITY_NOTICE_VALUE ) \
169 \
170ACTION( STUMPLESS_SEVERITY_INFO, STUMPLESS_SEVERITY_INFO_VALUE ) \
171 \
172ACTION( STUMPLESS_SEVERITY_DEBUG, STUMPLESS_SEVERITY_DEBUG_VALUE )
173
174# ifdef __cplusplus
175extern "C" {
176# endif
177
192
199# define STUMPLESS_SEVERITY_TRACE STUMPLESS_SEVERITY_DEBUG
200
221const char *
223
246stumpless_get_severity_enum( const char *severity_string );
247
272stumpless_get_severity_enum_from_buffer(const char *buffer, size_t length);
273
274# ifdef __cplusplus
275} /* extern "C" */
276# endif
277
278#endif /* __STUMPLESS_SEVERITY_H */
#define STUMPLESS_PUBLIC_FUNCTION
Marks functions that are provided for use by the library.
Definition config.h:31
Generic functionality to be used with STUMPLESS_FOREACH macros to allow for more generic definition o...
STUMPLESS_PUBLIC_FUNCTION enum stumpless_severity stumpless_get_severity_enum_from_buffer(const char *buffer, size_t length)
Gets the enum value corresponding to the given severity string in a buffer.
#define STUMPLESS_FOREACH_SEVERITY(ACTION)
A macro function that runs the provided action once for each severity, providing the symbol and value...
Definition severity.h:156
stumpless_severity
All possible severity codes available to log entries.
Definition severity.h:189
@ STUMPLESS_GENERATE_ENUM
Emergency: system is unusable.
Definition severity.h:190
STUMPLESS_PUBLIC_FUNCTION const char * stumpless_get_severity_string(enum stumpless_severity severity)
Gets the string representation of the given severity.
STUMPLESS_PUBLIC_FUNCTION enum stumpless_severity stumpless_get_severity_enum(const char *severity_string)
Gets the enum value corresponding to the given severity string.