Main Page
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
aerospike
as_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
23
#pragma once
24
25
#include <
aerospike/as_status.h
>
26
27
#include <citrusleaf/cf_atomic.h>
28
29
#include <stdarg.h>
30
#include <stdbool.h>
31
#include <stdio.h>
32
#include <stdint.h>
33
#include <stdlib.h>
34
#include <string.h>
35
36
/******************************************************************************
37
* TYPES
38
*****************************************************************************/
39
40
/**
41
* Log Level
42
*/
43
typedef
enum
as_log_level_e {
44
AS_LOG_LEVEL_OFF
= -1,
45
AS_LOG_LEVEL_ERROR
= 0,
46
AS_LOG_LEVEL_WARN
= 1,
47
AS_LOG_LEVEL_INFO
= 2,
48
AS_LOG_LEVEL_DEBUG
= 3,
49
AS_LOG_LEVEL_TRACE
= 4
50
}
as_log_level
;
51
52
/**
53
* Callback function for as_log related logging calls.
54
*
55
* The following is a simple log callback:
56
* ~~~~~~~~~~{.c}
57
* bool my_log_callback(
58
* as_log_level level, const char * func, const char * file, uint32_t line,
59
* const char * fmt, ...)
60
* {
61
* char msg[1024] = {0};
62
*
63
* va_list ap;
64
* va_start(ap, fmt);
65
* vsnprintf(msg, 1024, fmt, ap);
66
* msg[1023] = '\0';
67
* va_end(ap);
68
*
69
* fprintf(stderr, "[%s:%d][%s] %d - %s\n", file, line, func, level, msg);
70
*
71
* return true;
72
* }
73
* ~~~~~~~~~~
74
*
75
* The function should return true on success.
76
*
77
*
78
* @param level The log level of the message.
79
* @param func The function where the message was logged.
80
* @param file The file where the message was logged.
81
* @param line The line where the message was logged.
82
* @param fmt The format string used.
83
* @param ... The format argument.
84
*
85
* @return true if the message was logged. Otherwise false.
86
*
87
* @ingroup as_log_object
88
*/
89
typedef
bool (*
as_log_callback
)(
90
as_log_level
level,
const
char
* func,
const
char
* file, uint32_t line,
91
const
char
* fmt, ...);
92
93
/**
94
* Aerospike Client exposed logging functionality including:
95
* - Ability to control the verbosity of log messages.
96
* - Direct where log messages are sent to.
97
*
98
* Each @ref aerospike contains its own as_log instance: aerospike.log.
99
*
100
* ## Setting Log Level
101
*
102
* To set the log level for the aerospike client, simply use
103
* as_log_set_level() and pass in the client log to set.
104
*
105
* ~~~~~~~~~~{.c}
106
* as_log_set_level(&as->log, AS_LOG_LEVEL_INFO);
107
* ~~~~~~~~~~
108
*
109
* ## Redirecting Log Output
110
*
111
* By default, the logger sends log messages to STDERR.
112
*
113
* To change where log messages are sent, simply define a new @ref as_log_callback,
114
* and set it for the client using as_log_set_callback():
115
*
116
* ~~~~~~~~~~{.c}
117
* as_log_set_callback(&as->log, my_log_callback);
118
* ~~~~~~~~~~
119
*
120
* Where the `my_log_callback` could be defined as
121
*
122
* ~~~~~~~~~~{.c}
123
* bool my_log_callback(
124
* as_log_level level, const char * func, const char * file, uint32_t line,
125
* const char * fmt, ...)
126
* {
127
* char msg[1024] = {0};
128
* va_list ap;
129
* va_start(ap, fmt);
130
* vsnprintf(msg, 1024, fmt, ap);
131
* msg[1023] = '\0';
132
* va_end(ap);
133
* fprintf(stderr, "[%s:%d][%s] %d - %s\n", file, line, func, level, msg);
134
* return true;
135
* }
136
* ~~~~~~~~~~
137
*
138
* @ingroup client_objects
139
*/
140
typedef
struct
as_log_s {
141
142
/**
143
* Log Level
144
*/
145
cf_atomic32
level
;
146
147
/**
148
* Logging Callback
149
*/
150
cf_atomic_p
callback
;
151
152
}
as_log
;
153
154
/******************************************************************************
155
* FUNCTIONS
156
*****************************************************************************/
157
158
/**
159
* Initialize Log Context
160
*
161
* @relates as_log
162
*/
163
as_log
*
as_log_init
(
as_log
* log);
164
165
/**
166
* Set the level for the given log.
167
*
168
* @param log The log context.
169
* @param level The log level.
170
*
171
* @return true on success. Otherwise false.
172
*
173
* @relates as_log
174
*/
175
bool
as_log_set_level
(
as_log
* log,
as_log_level
level);
176
177
/**
178
* Set the callback for the given log
179
*
180
* @param log The log context.
181
* @param callback The log callback.
182
*
183
* @return true on success. Otherwise false.
184
*
185
* @relates as_log
186
*/
187
bool
as_log_set_callback
(
as_log
* log,
as_log_callback
callback);
as_log_level
as_log_level
Definition:
as_log.h:43
as_log::level
cf_atomic32 level
Definition:
as_log.h:145
AS_LOG_LEVEL_ERROR
Definition:
as_log.h:45
as_log::as_log_init
as_log * as_log_init(as_log *log)
as_log::as_log_set_callback
bool as_log_set_callback(as_log *log, as_log_callback callback)
AS_LOG_LEVEL_INFO
Definition:
as_log.h:47
as_log
Definition:
as_log.h:140
AS_LOG_LEVEL_OFF
Definition:
as_log.h:44
AS_LOG_LEVEL_TRACE
Definition:
as_log.h:49
as_log::callback
cf_atomic_p callback
Definition:
as_log.h:150
as_status.h
AS_LOG_LEVEL_DEBUG
Definition:
as_log.h:48
AS_LOG_LEVEL_WARN
Definition:
as_log.h:46
as_log_callback
bool(* as_log_callback)(as_log_level level, const char *func, const char *file, uint32_t line, const char *fmt,...)
Definition:
as_log.h:89
as_log::as_log_set_level
bool as_log_set_level(as_log *log, as_log_level level)