GRPC Core  0.13.1-pre1
 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-2016, 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_IMPL_CODEGEN_LOG_H
35 #define GRPC_IMPL_CODEGEN_LOG_H
36 
37 #include <stdlib.h> /* for abort() */
38 #include <stdarg.h>
39 
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /* GPR log API.
47 
48  Usage (within grpc):
49 
50  int argument1 = 3;
51  char* argument2 = "hello";
52  gpr_log(GPR_DEBUG, "format string %d", argument1);
53  gpr_log(GPR_INFO, "hello world");
54  gpr_log(GPR_ERROR, "%d %s!!", argument1, argument2); */
55 
56 /* The severity of a log message - use the #defines below when calling into
57  gpr_log to additionally supply file and line data */
58 typedef enum gpr_log_severity {
63 
64 /* Returns a string representation of the log severity */
65 const char *gpr_log_severity_string(gpr_log_severity severity);
66 
67 /* Macros to build log contexts at various severity levels */
68 #define GPR_DEBUG __FILE__, __LINE__, GPR_LOG_SEVERITY_DEBUG
69 #define GPR_INFO __FILE__, __LINE__, GPR_LOG_SEVERITY_INFO
70 #define GPR_ERROR __FILE__, __LINE__, GPR_LOG_SEVERITY_ERROR
71 
72 /* Log a message. It's advised to use GPR_xxx above to generate the context
73  * for each message */
74 GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity,
75  const char *format, ...);
76 
77 GPRAPI void gpr_log_message(const char *file, int line,
78  gpr_log_severity severity, const char *message);
79 
80 /* Log overrides: applications can use this API to intercept logging calls
81  and use their own implementations */
82 
83 typedef struct {
84  const char *file;
85  int line;
87  const char *message;
89 
90 typedef void (*gpr_log_func)(gpr_log_func_args *args);
92 
93 /* abort() the process if x is zero, having written a line to the log.
94 
95  Intended for internal invariants. If the error can be recovered from,
96  without the possibility of corruption, or might best be reflected via
97  an exception in a higher-level language, consider returning error code. */
98 #define GPR_ASSERT(x) \
99  do { \
100  if (!(x)) { \
101  gpr_log(GPR_ERROR, "assertion failed: %s", #x); \
102  abort(); \
103  } \
104  } while (0)
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* GRPC_IMPL_CODEGEN_LOG_H */
Definition: log.h:59
Definition: log.h:61
int line
Definition: log.h:85
Definition: log.h:83
#define GPRAPI
Definition: port_platform.h:359
const char * gpr_log_severity_string(gpr_log_severity severity)
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...)
GPRAPI void gpr_set_log_function(gpr_log_func func)
const char * message
Definition: log.h:87
const char * file
Definition: log.h:84
Definition: log.h:60
gpr_log_severity
Definition: log.h:58
gpr_log_severity severity
Definition: log.h:86
void(* gpr_log_func)(gpr_log_func_args *args)
Definition: log.h:90
GPRAPI void gpr_log_message(const char *file, int line, gpr_log_severity severity, const char *message)