3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <grpc/support/port_platform.h>
23 #include <android/log.h>
24 #include <grpc/support/log.h>
25 #include <grpc/support/time.h>
30 static android_LogPriority severity_to_log_priority(gpr_log_severity severity) {
32 case GPR_LOG_SEVERITY_DEBUG:
33 return ANDROID_LOG_DEBUG;
34 case GPR_LOG_SEVERITY_INFO:
35 return ANDROID_LOG_INFO;
36 case GPR_LOG_SEVERITY_ERROR:
37 return ANDROID_LOG_ERROR;
39 return ANDROID_LOG_DEFAULT;
42 void gpr_log(const char* file, int line, gpr_log_severity severity,
43 const char* format, ...) {
44 /* Avoid message construction if gpr_log_message won't log */
45 if (gpr_should_log(severity) == 0) {
50 va_start(args, format);
51 vasprintf(&message, format, args);
53 gpr_log_message(file, line, severity, message);
57 void gpr_default_log(gpr_log_func_args* args) {
58 const char* final_slash;
59 const char* display_file;
62 final_slash = strrchr(args->file, '/');
63 if (final_slash == NULL)
64 display_file = args->file;
66 display_file = final_slash + 1;
68 asprintf(&output, "%s:%d] %s", display_file, args->line, args->message);
70 __android_log_write(severity_to_log_priority(args->severity), "GRPC", output);
72 /* allocated by asprintf => use free, not gpr_free */
76 #endif /* GPR_ANDROID */