log_android.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
21 #ifdef GPR_ANDROID
22 
23 #include <android/log.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 
28 #include <grpc/support/log.h>
29 #include <grpc/support/time.h>
30 
31 static android_LogPriority severity_to_log_priority(gpr_log_severity severity) {
32  switch (severity) {
34  return ANDROID_LOG_DEBUG;
36  return ANDROID_LOG_INFO;
38  return ANDROID_LOG_ERROR;
39  }
40  return ANDROID_LOG_DEFAULT;
41 }
42 
43 void gpr_log(const char* file, int line, gpr_log_severity severity,
44  const char* format, ...) {
45  /* Avoid message construction if gpr_log_message won't log */
46  if (gpr_should_log(severity) == 0) {
47  return;
48  }
49  char* message = NULL;
50  va_list args;
51  va_start(args, format);
52  vasprintf(&message, format, args);
53  va_end(args);
55  free(message);
56 }
57 
59  const char* final_slash;
60  const char* display_file;
61  char* output = NULL;
62 
63  final_slash = strrchr(args->file, '/');
64  if (final_slash == NULL)
65  display_file = args->file;
66  else
67  display_file = final_slash + 1;
68 
69  asprintf(&output, "%s:%d] %s", display_file, args->line, args->message);
70 
71  __android_log_write(severity_to_log_priority(args->severity), "GRPC", output);
72 
73  /* allocated by asprintf => use free, not gpr_free */
74  free(output);
75 }
76 
77 #endif /* GPR_ANDROID */
http2_test_server.format
format
Definition: http2_test_server.py:118
log.h
bloat_diff.severity
def severity
Definition: bloat_diff.py:143
gpr_should_log
GPRAPI void GPRAPI int gpr_should_log(gpr_log_severity severity)
Definition: log.cc:67
string.h
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
time.h
GPR_LOG_SEVERITY_DEBUG
@ GPR_LOG_SEVERITY_DEBUG
Definition: include/grpc/impl/codegen/log.h:46
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
gpr_log_func_args
Definition: include/grpc/impl/codegen/log.h:77
GPR_LOG_SEVERITY_INFO
@ GPR_LOG_SEVERITY_INFO
Definition: include/grpc/impl/codegen/log.h:47
gpr_log_severity
gpr_log_severity
Definition: include/grpc/impl/codegen/log.h:45
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
gmock_output_test.output
output
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:175
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
GPR_LOG_SEVERITY_ERROR
@ GPR_LOG_SEVERITY_ERROR
Definition: include/grpc/impl/codegen/log.h:48
gpr_default_log
void gpr_default_log(gpr_log_func_args *args)
regen-readme.line
line
Definition: regen-readme.py:30
gpr_log_message
GPRAPI void gpr_log_message(const char *file, int line, gpr_log_severity severity, const char *message)
Definition: log.cc:81
port_platform.h


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:29