regify utility 2.1.0-0
 
Loading...
Searching...
No Matches
logging.h
1/*
2 * Copyright regify
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
64#ifndef REGIFY_UTIL_LOGGING_H
65#define REGIFY_UTIL_LOGGING_H
66/* Only need to export C interface if used by C++ source code */
67#ifdef __cplusplus
68extern "C" {
69#endif /* __cplusplus */
70
79#define RU_LOG_NONE 0
80
89#define RU_LOG_CRIT 1
90
94#define RU_LOG_WARN 2
95
100#define RU_LOG_INFO 3
101
106#define RU_LOG_VERB 4
107
113#define RU_LOG_DBUG 5
114
129typedef void (*ruLogFunc) (perm_ptr userData, uint32_t logLevel, trans_chars msg);
130
136typedef void (*ruCloseFunc) (perm_ptr userData);
137
141typedef int (*ruWriteFunc) (trans_chars buf, FILE* wh);
142
146typedef ptr ruPreCtx;
147
157
164RUAPI ruPreCtx ruPreCtxFree(ruPreCtx rpc, bool flush);
165
180RUAPI void ruPreLogSink(perm_ptr rpc, uint32_t logLevel, trans_chars msg);
181
186
197 perm_ptr closeCtx);
198
207RUAPI int32_t ruSinkWriteCb(ruSinkCtx rsc, ruWriteFunc writeCb);
208
221RUAPI int32_t ruSinkCtxPath(ruSinkCtx rsc, trans_chars filePath);
222
230
246RUAPI void ruFileLogSink(perm_ptr rsc, uint32_t logLevel, trans_chars msg);
247
254RUAPI void ruStdErrLogSink(perm_ptr udata, uint32_t logLevel, trans_chars msg);
255
263
273
299RUAPI void ruSetLogger(ruLogFunc logger, uint32_t logLevel, perm_ptr userData,
300 bool cleaned, bool threaded);
301
309RUAPI void ruLoggerUnblock(void);
310
314RUAPI void ruStopLogger(void);
315
320RUAPI void ruSetLogLevel(uint32_t logLevel);
321
326RUAPI uint32_t ruGetLogLevel(void);
327
336RUAPI bool ruDoesLog(uint32_t log_level);
337
338
365RUAPI void ruLogDbg(trans_chars filePath, trans_chars func, int32_t line, trans_chars format, ...);
366
378RUAPI void ruDoLog(uint32_t log_level, trans_chars filePath, trans_chars func,
379 int32_t line, trans_chars format, ...);
380
392RUAPI void ruDoLogV(uint32_t log_level, trans_chars filePath, trans_chars func,
393 int32_t line, trans_chars format, va_list args);
394
405RUAPI alloc_chars ruMakeLogMsgV(uint32_t log_level, trans_chars filePath,
406 trans_chars func, int32_t line,
407 trans_chars format, va_list args);
408
415RUAPI void ruRawLog(uint32_t log_level, trans_chars msg);
416
423RUAPI void ruFlushLog(void);
424
432RUAPI void ruLastLog(void);
433
444RUAPI char* ruMakeLogMsg(uint32_t log_level, trans_chars file, trans_chars func,
445 int32_t line, trans_chars format, ...);
446
454#define ruLog_(lvl, format, ...) ruMacStart { \
455 if(ruDoesLog(lvl)) { \
456 ruDoLog(lvl, __FILE__, __func__, __LINE__, format, __VA_ARGS__); \
457 } \
458} ruMacEnd
465#define ruCritLog(msg) ruLog_(RU_LOG_CRIT, "%s", msg)
466
472#define ruCritLogf(fmt, ...) ruLog_(RU_LOG_CRIT, fmt, __VA_ARGS__)
473
478#define ruWarnLog(msg) ruLog_(RU_LOG_WARN, "%s", msg)
479
485#define ruWarnLogf(fmt, ...) ruLog_(RU_LOG_WARN, fmt, __VA_ARGS__)
486
491#define ruInfoLog(msg) ruLog_(RU_LOG_INFO, "%s", msg)
492
498#define ruInfoLogf(fmt, ...) ruLog_(RU_LOG_INFO, fmt, __VA_ARGS__)
499
504#define ruVerbLog(msg) ruLog_(RU_LOG_VERB, "%s", msg)
505
511#define ruVerbLogf(fmt, ...) ruLog_(RU_LOG_VERB, fmt, __VA_ARGS__)
512
517#define ruDbgLog(msg) ruLog_(RU_LOG_DBUG, "%s", msg)
518
524#define ruDbgLogf(fmt, ...) ruLog_(RU_LOG_DBUG, fmt, __VA_ARGS__)
525
531#define ruDump8(msg, start) \
532 ruDbgLogf("%s @0x%x %02x %02x %02x %02x %02x %02x %02x %02x", msg, (start), \
533 (uint8_t)*(start), (uint8_t)*((start)+1), (uint8_t)*((start)+2), (uint8_t)*((start)+3), \
534 (uint8_t)*((start)+4), (uint8_t)*((start)+5), (uint8_t)*((start)+6), (uint8_t)*((start)+7))
535
541#define ruDump16(msg, start) \
542 ruDbgLogf("%s @0x%x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", msg, (start), \
543 (uint8_t)*(start), (uint8_t)*((start)+1), (uint8_t)*((start)+2), (uint8_t)*((start)+3), \
544 (uint8_t)*((start)+4), (uint8_t)*((start)+5), (uint8_t)*((start)+6), (uint8_t)*((start)+7), \
545 (uint8_t)*((start)+8), (uint8_t)*((start)+9), (uint8_t)*((start)+10), (uint8_t)*((start)+11), \
546 (uint8_t)*((start)+12), (uint8_t)*((start)+13), (uint8_t)*((start)+14), (uint8_t)*((start)+15))
547
551#ifdef __cplusplus
552}
553#endif /* __cplusplus */
554#endif //REGIFY_UTIL_LOGGING_H
void * ruCleaner
Definition regify-util.h:690
RUAPI void ruDoLogV(uint32_t log_level, trans_chars filePath, trans_chars func, int32_t line, trans_chars format, va_list args)
Logs the given parameters if logging is set.
RUAPI void ruRawLog(uint32_t log_level, trans_chars msg)
Sends the given message as is to the current log sink.
RUAPI ruPreCtx ruPreCtxNew(void)
Creates a new pre logging context for use with ruPreLogSink.
RUAPI perm_ptr ruGetLogCtx(void)
Returns the ruSetLogger userData in use by the current logger.
RUAPI int32_t ruSinkWriteCb(ruSinkCtx rsc, ruWriteFunc writeCb)
Allow substituting fputs call with custom implementation.
int(* ruWriteFunc)(trans_chars buf, FILE *wh)
The type of function to pass to ruSinkWriteCb to substitute fputs.
Definition logging.h:141
RUAPI void ruFileLogSink(perm_ptr rsc, uint32_t logLevel, trans_chars msg)
A log sink that logs into the filepath set in the given ruSinkCtx.
RUAPI uint32_t ruGetLogLevel(void)
Returns the currently set log level.
RUAPI ruPreCtx ruPreCtxFree(ruPreCtx rpc, bool flush)
Frees the given ruPreCtx.
RUAPI char * ruMakeLogMsg(uint32_t log_level, trans_chars file, trans_chars func, int32_t line, trans_chars format,...)
RUAPI alloc_chars ruMakeLogMsgV(uint32_t log_level, trans_chars filePath, trans_chars func, int32_t line, trans_chars format, va_list args)
RUAPI void ruFlushLog(void)
Sends a NULL message with log level RU_LOG_CRIT to the current log sink, usually causing it to flush ...
RUAPI void ruLastLog(void)
Sends a NULL message with log level RU_LOG_NONE to the current log sink, usually causing it to close ...
void(* ruCloseFunc)(perm_ptr userData)
The type of function to pass to ruSinkCtxNew which will be called when ruFileLogSink has closed its l...
Definition logging.h:136
RUAPI void ruLogDbg(trans_chars filePath, trans_chars func, int32_t line, trans_chars format,...)
Prints given parameters to stdout.
RUAPI void ruSetLogLevel(uint32_t logLevel)
Adjusts the current log level.
RUAPI int32_t ruSinkCtxPath(ruSinkCtx rsc, trans_chars filePath)
Allows changing the file path of the given ruSinkCtx.
RUAPI ruSinkCtx ruSinkCtxFree(ruSinkCtx rsc)
Frees the given ruSinkCtx after ruStopLogger has been called. This must not be called when the contex...
RUAPI void ruLoggerUnblock(void)
Unblocks any thread blocked on logging by removing the size limit of the log queue.
RUAPI void ruStopLogger(void)
Stop the current logger and flush the queue before returning.
ptr ruPreCtx
Opaque pointer to ruPreLogSink object.
Definition logging.h:146
RUAPI void ruDoLog(uint32_t log_level, trans_chars filePath, trans_chars func, int32_t line, trans_chars format,...)
Logs the given parameters if logging is set.
RUAPI bool ruDoesLog(uint32_t log_level)
Returns whether the given log level should log.
RUAPI void ruSetLogger(ruLogFunc logger, uint32_t logLevel, perm_ptr userData, bool cleaned, bool threaded)
Sets the global logging function for this process.
ptr ruSinkCtx
Opaque pointer to ruFileLogSink object.
Definition logging.h:185
RUAPI void ruPreLogSink(perm_ptr rpc, uint32_t logLevel, trans_chars msg)
Pre logging sink to store log entries until a final log sink has been established.
void(* ruLogFunc)(perm_ptr userData, uint32_t logLevel, trans_chars msg)
The type of function to pass to ruSetLogger in order to hook up logging.
Definition logging.h:129
RUAPI ruSinkCtx ruSinkCtxNew(trans_chars filePath, ruCloseFunc closeCb, perm_ptr closeCtx)
Creates a new context to use with ruFileLogSink.
RUAPI ruCleaner ruGetCleaner(void)
Public ruCleaner instance that is used by the logger when cleaning is enabled.
RUAPI void ruStdErrLogSink(perm_ptr udata, uint32_t logLevel, trans_chars msg)
A convenience logging implementation that logs to stderr.
const void * perm_ptr
A permanent pointer.
Definition regify-util.h:277
const char * trans_chars
A transient NULL terminated string pointer.
Definition regify-util.h:186
char * alloc_chars
An allocated NULL terminated string pointer.
Definition regify-util.h:199
void * ptr
A generic pointer.
Definition regify-util.h:304