1 /*
2   Copyright 2020 Northern.tech AS
3 
4   This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6   This program is free software; you can redistribute it and/or modify it
7   under the terms of the GNU General Public License as published by the
8   Free Software Foundation; version 3.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
18 
19   To the extent this program is licensed as part of the Enterprise
20   versions of CFEngine, the applicable Commercial Open Source License
21   (COSL) may apply to this file if you as a licensee so wish it. See
22   included file COSL.txt.
23 */
24 
25 #ifndef CFENGINE_LOGGING_PRIV_H
26 #define CFENGINE_LOGGING_PRIV_H
27 
28 /*
29  * This interface is private and intended only for use by logging extensions (such as one defined in libpromises).
30  */
31 
32 typedef struct LoggingPrivContext LoggingPrivContext;
33 
34 typedef char *(*LoggingPrivLogHook)(LoggingPrivContext *context, LogLevel level, const char *message);
35 
36 struct LoggingPrivContext
37 {
38     LoggingPrivLogHook log_hook;
39     void *param;
40 
41     /**
42      * Generally the log_hook runs whenever the message is printed either to
43      * console or to syslog. You can set this to *additionally* run the hook
44      * when the message level is <= force_hook_level.
45      *
46      * @NOTE the default setting of 0 equals to CRIT level, which is good as
47      *       default since the CRIT messages are always printed anyway, so
48      *       the log_hook runs anyway.
49      */
50     LogLevel force_hook_level;
51 };
52 
53 /**
54  * @brief Attaches context to logging for current thread
55  */
56 void LoggingPrivSetContext(LoggingPrivContext *context);
57 
58 /**
59  * @brief Retrieves logging context for current thread
60  */
61 LoggingPrivContext *LoggingPrivGetContext(void);
62 
63 /**
64  * @brief Set logging (syslog) and reporting (stdout) level for current thread
65  */
66 void LoggingPrivSetLevels(LogLevel log_level, LogLevel report_level);
67 
68 #endif
69