GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
log.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef GRPC_SUPPORT_LOG_H
35 #define GRPC_SUPPORT_LOG_H
36
37 #include <stdlib.h> /* for abort() */
38 #include <stdarg.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 /* GPR log API.
45
46 Usage (within grpc):
47
48 int argument1 = 3;
49 char* argument2 = "hello";
50 gpr_log(GPR_DEBUG, "format string %d", argument1);
51 gpr_log(GPR_INFO, "hello world");
52 gpr_log(GPR_ERROR, "%d %s!!", argument1, argument2); */
53
54 /* The severity of a log message - use the #defines below when calling into
55 gpr_log to additionally supply file and line data */
56 typedef enum gpr_log_severity {
57 GPR_LOG_SEVERITY_DEBUG,
58 GPR_LOG_SEVERITY_INFO,
59 GPR_LOG_SEVERITY_ERROR
60 } gpr_log_severity;
61
62 /* Returns a string representation of the log severity */
63 const char *gpr_log_severity_string(gpr_log_severity severity);
64
65 /* Macros to build log contexts at various severity levels */
66 #define GPR_DEBUG __FILE__, __LINE__, GPR_LOG_SEVERITY_DEBUG
67 #define GPR_INFO __FILE__, __LINE__, GPR_LOG_SEVERITY_INFO
68 #define GPR_ERROR __FILE__, __LINE__, GPR_LOG_SEVERITY_ERROR
69
70 /* Log a message. It's advised to use GPR_xxx above to generate the context
71 * for each message */
72 void gpr_log(const char *file, int line, gpr_log_severity severity,
73 const char *format, ...);
74
75 void gpr_log_message(const char *file, int line, gpr_log_severity severity,
76 const char *message);
77
78 /* Log overrides: applications can use this API to intercept logging calls
79 and use their own implementations */
80
81 typedef struct {
82 const char *file;
83 int line;
84 gpr_log_severity severity;
85 const char *message;
86 } gpr_log_func_args;
87
88 typedef void (*gpr_log_func)(gpr_log_func_args *args);
89 void gpr_set_log_function(gpr_log_func func);
90
91 /* abort() the process if x is zero, having written a line to the log.
92
93 Intended for internal invariants. If the error can be recovered from,
94 without the possibility of corruption, or might best be reflected via
95 an exception in a higher-level language, consider returning error code. */
96 #define GPR_ASSERT(x) \
97 do { \
98 if (!(x)) { \
99 gpr_log(GPR_ERROR, "assertion failed: %s", #x); \
100 abort(); \
101 } \
102 } while (0)
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif /* GRPC_SUPPORT_LOG_H */
GPR_LOG_SEVERITY_INFO
Definition: log.h:58
gpr_log_func_args::line
int line
Definition: log.h:83
gpr_log_func_args
Definition: log.h:81
gpr_log_severity
gpr_log_severity
Definition: log.h:56
gpr_log_severity_string
const char * gpr_log_severity_string(gpr_log_severity severity)
gpr_log_func_args::message
const char * message
Definition: log.h:85
gpr_log_func_args::file
const char * file
Definition: log.h:82
gpr_log_func
void(* gpr_log_func)(gpr_log_func_args *args)
Definition: log.h:88
gpr_log
void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...)
gpr_log_message
void gpr_log_message(const char *file, int line, gpr_log_severity severity, const char *message)
gpr_set_log_function
void gpr_set_log_function(gpr_log_func func)
gpr_log_func_args::severity
gpr_log_severity severity
Definition: log.h:84
GPR_LOG_SEVERITY_ERROR
Definition: log.h:59
GPR_LOG_SEVERITY_DEBUG
Definition: log.h:57