Debian Codegraph @

src/nvme/log.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 /*
3 * Copyright (c) 2021 Martin Wilck, SUSE LLC
4 */
5 #ifndef _LOG_H
6 #define _LOG_H
7
8 #include <stdbool.h>
9 #include <syslog.h>
10
11 /* for nvme_root_t */
12 #include <nvme/tree.h>
13
14 #ifndef MAX_LOGLEVEL
15 # define MAX_LOGLEVEL LOG_DEBUG
16 #endif
17 #ifndef DEFAULT_LOGLEVEL
18 # define DEFAULT_LOGLEVEL LOG_NOTICE
19 #endif
20
21 /**
22 * DOC: log.h
23 *
24 * logging functions
25 */
26
27 /**
28 * nvme_init_logging() - Initialize logging
29 * @r: nvme_root_t context
30 * @lvl: Logging level to set
31 * @log_pid: Boolean to enable logging of the PID
32 * @log_tstamp: Boolean to enable logging of the timestamp
33 *
34 * Sets the default logging variables for the library.
35 */
36 void nvme_init_logging(nvme_root_t r, int lvl, bool log_pid, bool log_tstamp);
37
38 /**
39 * nvme_init_default_logging() - Initialize default (fallback) logging
40 * @fp: File descriptor for logging messages
41 * @lvl: Logging level to set
42 * @log_pid: Boolean to enable logging of the PID
43 * @log_tstamp: Boolean to enable logging of the timestamp
44 *
45 * Sets the default logging settings for the library in case the root object
46 * is absent.
47 */
48 void nvme_init_default_logging(FILE *fp, int lvl, bool log_pid, bool log_tstamp);
49
50 /**
51 * nvme_get_logging_level() - Get current logging level
52 * @r: nvme_root_t context
53 * @log_pid: Pointer to store a current value of logging of
54 * the PID flag at (optional).
55 * @log_tstamp: Pointer to store a current value of logging of
56 * the timestamp flag at (optional).
57 *
58 * Retrieves current values of logging variables.
59 *
60 * Return: current log level value or DEFAULT_LOGLEVEL if not initialized.
61 */
62 int nvme_get_logging_level(nvme_root_t r, bool *log_pid, bool *log_tstamp);
63
64 /**
65 * nvme_set_root() - Set nvme_root_t context
66 * @r: nvme_root_t context
67 *
68 * In order to be able to log from code paths where no root object is passed in
69 * via the arguments use the the default one which can be set via this call.
70 * When creating a new root object with @nvme_create_root the global root object
71 * will be set as well. This means the global root object is always pointing to
72 * the latest created root object. Note the first @nvme_free_tree call will reset
73 * the global root object.
74 *
75 * This function is deprecated. Use nvme_init_default_logging or/and
76 * nvme_init_logging instead.
77 */
78 void nvme_set_root(nvme_root_t r) __attribute__((deprecated));
79
80 /**
81 * nvme_set_debug - Set NVMe command debugging output
82 * @debug: true to enable or false to disable
83 *
84 * This function is deprecated. Use nvme_init_default_logging instead.
85 */
86 void nvme_set_debug(bool debug) __attribute__((deprecated));
87
88 /**
89 * nvme_get_debug - Get NVMe command debugging output
90 *
91 * This function is deprecated. Use nvme_get_logging_level instead.
92 *
93 * Return: false if disabled or true if enabled.
94 */
95 bool nvme_get_debug(void) __attribute__((deprecated));
96
97 #endif /* _LOG_H */