Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
modules
base
target
Linux-x86_64
include
citrusleaf
target/Linux-x86_64/include/citrusleaf/cf_log.h
Go to the documentation of this file.
1
/******************************************************************************
2
* Copyright 2008-2013 by Aerospike.
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
6
* deal in the Software without restriction, including without limitation the
7
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
* sell 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
19
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
* IN THE SOFTWARE.
21
*****************************************************************************/
22
#pragma once
23
24
#include <stdarg.h>
25
#include <citrusleaf/cf_atomic.h>
26
27
extern
cf_atomic32
g_log_level
;
28
extern
cf_atomic_p
g_log_callback
;
29
30
#define G_LOG_LEVEL ((int)cf_atomic32_get(g_log_level))
31
#define G_LOG_CB ((cf_log_callback)cf_atomic_p_get(g_log_callback))
32
33
//====================================================================
34
// Public API
35
//
36
37
/**
38
* Log escalation level.
39
*/
40
typedef
enum
{
41
/**
42
* Pass this in cf_set_log_level() to suppress all logging.
43
*/
44
CF_NO_LOGGING
= -1,
45
46
/**
47
* Error condition has occurred.
48
*/
49
CF_ERROR
,
50
51
/**
52
* Unusual non-error condition has occurred.
53
*/
54
CF_WARN
,
55
56
/**
57
* Normal information message.
58
*/
59
CF_INFO
,
60
61
/**
62
* Message used for debugging purposes.
63
*/
64
CF_DEBUG
65
}
cf_log_level
;
66
67
/**
68
* A callback function of this signature may be passed in cf_set_log_callback(),
69
* so the caller can channel Aerospike client logs as desired.
70
*
71
* @param level log level for this log statement
72
* @param fmt format string for this log statement (does not end
73
* with '\n')
74
* @param ... arguments corresponding to conversion characters in
75
* format string
76
*/
77
typedef
void (*
cf_log_callback
)(
cf_log_level
level,
const
char
* fmt, ...);
78
79
/**
80
* Set logging level filter.
81
* <p>
82
* Thread-safe - may be called at any time.
83
* <p>
84
* To suppress logs, either set log level to CF_NO_LOGGING or ignore callbacks.
85
*
86
* @param level only show logs at this or more urgent level
87
*/
88
static
inline
void
cf_set_log_level
(
cf_log_level
level)
89
{
90
cf_atomic32_set
(&
g_log_level
, (cf_atomic32)level);
91
}
92
93
/**
94
* Set optional log callback.
95
* <p>
96
* Thread-safe - may be called at any time.
97
* <p>
98
* If no callback is registered, the Aerospike client writes logs to stderr.
99
* <p>
100
* To suppress logs, either set log level to CF_NO_LOGGING or ignore callbacks.
101
*
102
* @param callback cf_log_callback implementation
103
*/
104
static
inline
void
cf_set_log_callback
(
cf_log_callback
callback)
105
{
106
if
(callback) {
107
cf_atomic_p_set
(&
g_log_callback
, (cf_atomic_p)callback);
108
}
109
}
110
111
static
inline
int
cf_info_enabled
()
112
{
113
return
CF_INFO
<=
G_LOG_LEVEL
;
114
}
115
116
static
inline
int
cf_debug_enabled
()
117
{
118
return
CF_DEBUG
<=
G_LOG_LEVEL
;
119
}