stumpless 2.2.0
载入中...
搜索中...
未找到
target.h
浏览该文件的文档.
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
27#ifndef __STUMPLESS_TARGET_H
28#define __STUMPLESS_TARGET_H
29
30#include <stdarg.h>
31#include <stdbool.h>
32#include <stddef.h>
33#include <stdio.h>
34#include <stumpless/config.h>
35#include <stumpless/entry.h>
36#include <stumpless/id.h>
37#include <stumpless/generator.h>
38
40#define STUMPLESS_DEFAULT_TARGET_NAME "stumpless-default"
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
47#define STUMPLESS_BUFFER_TARGET_VALUE 0
48
50#define STUMPLESS_FILE_TARGET_VALUE 1
51
53#define STUMPLESS_FUNCTION_TARGET_VALUE 2
54
56#define STUMPLESS_JOURNALD_TARGET_VALUE 3
57
59#define STUMPLESS_NETWORK_TARGET_VALUE 4
60
62#define STUMPLESS_SOCKET_TARGET_VALUE 5
63
65#define STUMPLESS_STREAM_TARGET_VALUE 6
66
68#define STUMPLESS_WINDOWS_EVENT_LOG_TARGET_VALUE 7
69
71#define STUMPLESS_SQLITE3_TARGET_VALUE 8
72
78#define STUMPLESS_CHAIN_TARGET_VALUE 9
79
86#define STUMPLESS_FOREACH_TARGET_TYPE( ACTION )\
87ACTION( STUMPLESS_BUFFER_TARGET, STUMPLESS_BUFFER_TARGET_VALUE )\
88ACTION( STUMPLESS_FILE_TARGET, STUMPLESS_FILE_TARGET_VALUE )\
89ACTION( STUMPLESS_FUNCTION_TARGET, STUMPLESS_FUNCTION_TARGET_VALUE )\
90ACTION( STUMPLESS_JOURNALD_TARGET, STUMPLESS_JOURNALD_TARGET_VALUE )\
91ACTION( STUMPLESS_NETWORK_TARGET, STUMPLESS_NETWORK_TARGET_VALUE )\
92ACTION( STUMPLESS_SOCKET_TARGET, STUMPLESS_SOCKET_TARGET_VALUE )\
93ACTION( STUMPLESS_STREAM_TARGET, STUMPLESS_STREAM_TARGET_VALUE )\
94ACTION( STUMPLESS_WINDOWS_EVENT_LOG_TARGET, STUMPLESS_WINDOWS_EVENT_LOG_TARGET_VALUE )\
95ACTION( STUMPLESS_SQLITE3_TARGET, STUMPLESS_SQLITE3_TARGET_VALUE )\
96ACTION( STUMPLESS_CHAIN_TARGET, STUMPLESS_CHAIN_TARGET_VALUE )
97
104
105// needed so that we can define the filter function type before targets
106struct stumpless_target;
107
133typedef bool ( *stumpless_filter_func_t )(
134 const struct stumpless_target *target,
135 const struct stumpless_entry *entry );
136
199
233int
235 const struct stumpless_entry *entry );
236
286int
288 int priority,
289 const char *message,
290 ... );
291
332int
334 int priority,
335 const char *message );
336
383int
385 const char *message,
386 ... );
387
426int
428 const char *message );
429
461void
463
464/*
465 * Gets the current console stream where logs are written to.
466 *
467 * **Thread Safety: MT-Safe**
468 * This function is thread safe. Atomic variables are used to store and
469 * retrieve the console stream.
470 *
471 * **Async Signal Safety: AS-Safe**
472 * This function is safe to call from signal handlers.
473 *
474 * **Async Cancel Safety: AC-Safe**
475 * This function is safe to call from threads that may be ansynchronously
476 * cancelled.
477 *
478 * @since release v2.1.0
479 *
480 * @return The current stream where messages are logged to on setting the
481 * the CONS option.
482 */
484FILE *
486
518struct stumpless_target *
520
542int
544
589struct stumpless_target *
591
619int
620stumpless_get_option( const struct stumpless_target *target, int option );
621
649const char *
651
679const char *
681
712
741int
743
770const char *
772
803struct stumpless_target *
805
829void
831
855void
857
882struct stumpless_target *
884 int default_facility );
885
910struct stumpless_target *
911stumpless_set_option( struct stumpless_target *target, int option );
912
940struct stumpless_target *
942 const char *app_name );
943
972struct stumpless_target *
974 const char *msgid );
975
1003struct stumpless_target *
1006
1037struct stumpless_target *
1039
1069const struct stumpless_target *
1071
1116int
1118 struct stumpless_entry *entry,
1119 const char *file,
1120 int line,
1121 const char *func );
1122
1183int
1185 int priority,
1186 const char *file,
1187 int line,
1188 const char *func,
1189 const char *message,
1190 ... );
1191
1243int
1245 int priority,
1246 const char *file,
1247 int line,
1248 const char *func,
1249 const char *message );
1250
1308int
1310 const char *file,
1311 int line,
1312 const char *func,
1313 const char *message,
1314 ... );
1315
1365int
1367 const char *file,
1368 int line,
1369 const char *func,
1370 const char *message );
1371
1396struct stumpless_target *
1397stumpless_unset_option( struct stumpless_target *target, int option );
1398
1443int
1445 int priority,
1446 const char *message,
1447 va_list subs );
1448
1490int
1492 const char *message,
1493 va_list subs );
1494
1549int
1551 int priority,
1552 const char *file,
1553 int line,
1554 const char *func,
1555 const char *message,
1556 va_list subs );
1557
1609int
1611 const char *file,
1612 int line,
1613 const char *func,
1614 const char *message,
1615 va_list subs );
1616
1639const char *
1641
1642
1643#ifdef __cplusplus
1644} /* extern "C" */
1645#endif
1646
1647#endif /* __STUMPLESS_TARGET_H */
#define STUMPLESS_PUBLIC_FUNCTION
Marks functions that are provided for use by the library.
定义 config.h:31
Types and functions for creating and modifying entries.
#define STUMPLESS_MAX_APP_NAME_LENGTH
The maximum length of an app name, as specified by RFC 5424.
定义 entry.h:43
#define STUMPLESS_MAX_MSGID_LENGTH
The maximum length of a msgid, as specified by RFC 5424.
定义 entry.h:46
Generic functionality to be used with STUMPLESS_FOREACH macros to allow for more generic definition o...
The identification for targets within the library.
void * stumpless_id_t
定义 id.h:30
A log entry.
定义 entry.h:60
A target that log entries can be sent to.
定义 target.h:140
stumpless_filter_func_t filter
A filter function used to determine if a given entry should be processed by this target or ignored.
定义 target.h:190
char * name
The name of this target.
定义 target.h:157
stumpless_id_t id
A unique identifier of this target.
定义 target.h:142
size_t name_length
The number of characters in the name.
定义 target.h:159
char default_app_name[STUMPLESS_MAX_APP_NAME_LENGTH]
The app name used for messages without one provided.
定义 target.h:169
int mask
The log mask for the target.
定义 target.h:181
size_t default_app_name_length
The number of characters in the default app name.
定义 target.h:171
void * mutex
A pointer to a mutex which protects all target fields.
定义 target.h:196
int default_prival
The prival used for messages without a severity or facility provided.
定义 target.h:163
int options
A bitwise or of all options set on the target.
定义 target.h:161
char default_msgid[STUMPLESS_MAX_MSGID_LENGTH]
The msgid used for messages without one provided.
定义 target.h:177
enum stumpless_target_type type
The type of this target.
定义 target.h:147
size_t default_msgid_length
The number of characters in the default msgid.
定义 target.h:179
struct stumpless_target * stumpless_set_target_mask(struct stumpless_target *target, int mask)
Sets the log mask of a target.
int stumpless_add_log_str(struct stumpless_target *target, int priority, const char *message)
Adds a log message with a priority to a given target.
struct stumpless_target * stumpless_set_default_facility(struct stumpless_target *target, int default_facility)
Sets the default facility of a target.
int stumpless_add_message_str(struct stumpless_target *target, const char *message)
Adds a string message to a given target.
struct stumpless_target * stumpless_set_option(struct stumpless_target *target, int option)
Sets an option on a target.
struct stumpless_target * stumpless_get_current_target(void)
Gets the current target.
FILE * stumpless_get_cons_stream(void)
int stumpless_trace_message_str(struct stumpless_target *target, const char *file, int line, const char *func, const char *message)
Adds a message to a given target, along with the file, line, and function information specified in a ...
const struct stumpless_target * stumpless_target_is_open(const struct stumpless_target *target)
Checks to see if the given target is open.
struct stumpless_target * stumpless_get_default_target(void)
Gets the default target.
void stumpless_set_current_target(struct stumpless_target *target)
Sets the target used when one is not provided.
int vstumpless_add_log(struct stumpless_target *target, int priority, const char *message, va_list subs)
Adds a log message with a priority to a given target.
const char * stumpless_get_target_type_string(enum stumpless_target_type target_type)
Gets the string representation of the given target_type.
int stumpless_trace_log(struct stumpless_target *target, int priority, const char *file, int line, const char *func, const char *message,...)
Adds a log message with a priority to a given target, along with the file, line, and function informa...
void stumpless_close_target(struct stumpless_target *target)
Closes a target.
struct stumpless_target * stumpless_set_target_default_msgid(struct stumpless_target *target, const char *msgid)
Sets the default msgid for a given target.
int stumpless_add_message(struct stumpless_target *target, const char *message,...)
Adds a message to a given target.
struct stumpless_target * stumpless_unset_option(struct stumpless_target *target, int option)
Unsets an option on a target.
struct stumpless_target * stumpless_open_target(struct stumpless_target *target)
Opens a target that has already been created and configured.
const char * stumpless_get_target_default_msgid(const struct stumpless_target *target)
Returns the default msgid of the given target.
int stumpless_get_target_mask(const struct stumpless_target *target)
Gets the log mask of a target.
stumpless_target_type
Types of targets that may be created.
定义 target.h:101
@ STUMPLESS_GENERATE_ENUM
定义 target.h:102
int vstumpless_trace_message(struct stumpless_target *target, const char *file, int line, const char *func, const char *message, va_list subs)
Adds a message to a given target, along with the file, line, and function information specified in a ...
#define STUMPLESS_FOREACH_TARGET_TYPE(ACTION)
A macro function that runs the provided action once for each target_type, providing the symbol and va...
定义 target.h:86
int stumpless_trace_entry(struct stumpless_target *target, struct stumpless_entry *entry, const char *file, int line, const char *func)
Adds an entry into a given target.
void stumpless_set_cons_stream(FILE *stream)
Sets the console stream to write logs to.
int vstumpless_add_message(struct stumpless_target *target, const char *message, va_list subs)
Adds a message to a given target.
const char * stumpless_get_target_default_app_name(const struct stumpless_target *target)
Returns the default app name of the given target.
int stumpless_add_entry(struct stumpless_target *target, const struct stumpless_entry *entry)
Adds an entry into a given target.
bool(* stumpless_filter_func_t)(const struct stumpless_target *target, const struct stumpless_entry *entry)
A function that determines whether a given entry should be sent to a given target.
定义 target.h:133
int vstumpless_trace_log(struct stumpless_target *target, int priority, const char *file, int line, const char *func, const char *message, va_list subs)
Adds a log message with a priority to a given target, along with the file, line, and function informa...
const char * stumpless_get_target_name(const struct stumpless_target *target)
Returns the name of the given target.
int stumpless_get_default_facility(const struct stumpless_target *target)
Gets the default facility of a target.
struct stumpless_target * stumpless_set_target_default_app_name(struct stumpless_target *target, const char *app_name)
Sets the default app name for a given target.
int stumpless_trace_message(struct stumpless_target *target, const char *file, int line, const char *func, const char *message,...)
Adds a message to a given target, along with the file, line, and function information specified in a ...
int stumpless_get_option(const struct stumpless_target *target, int option)
Gets a given option of a target.
struct stumpless_target * stumpless_set_target_filter(struct stumpless_target *target, stumpless_filter_func_t filter)
Sets the filter used to determine whether entries should be logged by a given target.
int stumpless_add_log(struct stumpless_target *target, int priority, const char *message,...)
Adds a log message with a priority to a given target.
stumpless_filter_func_t stumpless_get_target_filter(const struct stumpless_target *target)
Returns the current filter used by the given target to determine if entries should be allowed through...
int stumpless_trace_log_str(struct stumpless_target *target, int priority, const char *file, int line, const char *func, const char *message)
Adds a log message with a priority to a given target, along with the file, line, and function informa...