CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
log_private.h
1#pragma once
2
3#include <cx/container.h>
4#include <cx/thread.h>
5#include <cx/utils/lazyinit.h>
6#include "log.h"
7
8#define LOG_INITIAL_QUEUE_SIZE 32
9#define LOG_MAX_QUEUE_SIZE 262144
10
11extern atomic(bool) _log_running;
12extern Mutex _log_run_lock;
13extern Thread* _log_thread;
14
15typedef struct LogDest {
16 LogCategory* catfilter;
17 LogDestMsg msgfunc;
18 LogDestBatchDone batchfunc;
19 LogDestClose closefunc;
20 void* userdata;
21 int maxlevel;
22} LogDest;
23saDeclarePtr(LogDest);
24
25typedef struct LogEntry LogEntry;
26typedef struct LogEntry {
27 LogEntry* _next; // chain for log batches, internal use only
28 int64 timestamp;
29 LogCategory* cat;
30 string msg;
31 int level;
32} LogEntry;
33saDeclarePtr(LogEntry);
34
35// cached for performance, can safely be non-atomic
36extern int _log_max_level;
37
38extern PrQueue _log_queue;
39
40// protects _log_dests and _log_categories (structures that are accessed from the log thread)
41extern Mutex _log_op_lock;
42extern sa_LogDest _log_dests;
43extern hashtable _log_categories;
44
45extern LazyInitState _logInitState;
46
47void logCheckInit(void);
48void logDestroyEnt(_In_ LogEntry* ent);
49void logQueueAdd(_In_ LogEntry* ent);
50void logThreadCreate(void);
51
52// does NOT free dhandle, caller is responsible for that!
53bool logUnregisterDestLocked(_In_ LogDest* dhandle);
54
55_meta_inline bool applyCatFilter(_In_opt_ LogCategory* filtercat, _In_ LogCategory* testcat)
56{
57 if (!filtercat) {
58 // no filter, we want all categories except for private categories
59 return !testcat || !testcat->priv;
60 }
61
62 return filtercat == testcat;
63}
Generic type-safe containers with runtime type system integration.
#define saDeclarePtr(name)
Definition sarray.h:98
struct LogDest LogDest
Opaque handle to a registered log destination.
Definition log.h:87
void(* LogDestMsg)(int level, LogCategory *cat, int64 timestamp, strref msg, uint32 batchid, void *userdata)
Definition log.h:120
void(* LogDestBatchDone)(uint32 batchid, void *userdata)
Definition log.h:130
void(* LogDestClose)(void *userdata)
Definition log.h:138
Threading system aggregated header.
Thread-safe lazy initialization.
Core logging system API.
State tracker for lazy initialization.
Definition lazyinit.h:40
Definition mutex.h:60