summaryrefslogtreecommitdiffstats
path: root/src/nvme/log.h
blob: 80c642aa4204d4e31b8cc0e4698de6511e6d73ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-License-Identifier: LGPL-2.1-or-later
/*
 * Copyright (c) 2021 Martin Wilck, SUSE LLC
 */
#ifndef _LOG_H
#define _LOG_H

#include <stdbool.h>
#include <syslog.h>

/* for nvme_root_t */
#include "tree.h"

#ifndef MAX_LOGLEVEL
#  define MAX_LOGLEVEL LOG_DEBUG
#endif
#ifndef DEFAULT_LOGLEVEL
#  define DEFAULT_LOGLEVEL LOG_NOTICE
#endif

/**
 * DOC: log.h
 *
 * logging functions
 */

/**
 * nvme_init_logging() - Initialize logging
 * @r:		nvme_root_t context
 * @lvl:	Logging level to set
 * @log_pid:	Boolean to enable logging of the PID
 * @log_tstamp:	Boolean to enable logging of the timestamp
 *
 * Sets the default logging variables for the library.
 */
void nvme_init_logging(nvme_root_t r, int lvl, bool log_pid, bool log_tstamp);

/**
 * nvme_init_default_logging() - Initialize default (fallback) logging
 * @fp:		File descriptor for logging messages
 * @lvl:	Logging level to set
 * @log_pid:	Boolean to enable logging of the PID
 * @log_tstamp:	Boolean to enable logging of the timestamp
 *
 * Sets the default logging settings for the library in case the root object
 * is absent.
 */
void nvme_init_default_logging(FILE *fp, int lvl, bool log_pid, bool log_tstamp);

/**
 * nvme_get_logging_level() - Get current logging level
 * @r:		nvme_root_t context
 * @log_pid:	Pointer to store a current value of logging of
 *		the PID flag at (optional).
 * @log_tstamp:	Pointer to store a current value of logging of
 *		the timestamp flag at (optional).
 *
 * Retrieves current values of logging variables.
 *
 * Return: current log level value or DEFAULT_LOGLEVEL if not initialized.
 */
int nvme_get_logging_level(nvme_root_t r, bool *log_pid, bool *log_tstamp);

/**
 * nvme_set_root() - Set nvme_root_t context
 * @r:		nvme_root_t context
 *
 * In order to be able to log from code paths where no root object is passed in
 * via the arguments use the the default one which can be set via this call.
 * When creating a new root object with @nvme_create_root the global root object
 * will be set as well. This means the global root object is always pointing to
 * the latest created root object. Note the first @nvme_free_tree call will reset
 * the global root object.
 *
 * This function is deprecated. Use nvme_init_default_logging or/and
 * nvme_init_logging instead.
 */
void nvme_set_root(nvme_root_t r) __attribute__((deprecated));

/**
 * nvme_set_debug - Set NVMe command debugging output
 * @debug:	true to enable or false to disable
 *
 * This function is deprecated. Use nvme_init_default_logging instead.
 */
void nvme_set_debug(bool debug) __attribute__((deprecated));

/**
 * nvme_get_debug - Get NVMe command debugging output
 *
 * This function is deprecated. Use nvme_get_logging_level instead.
 *
 * Return: false if disabled or true if enabled.
 */
bool nvme_get_debug(void) __attribute__((deprecated));

#endif /* _LOG_H */