logging.h revision 3fec9ac0d5af1358d216eb2fdc2000ec0205f3f0
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_RUNTIME_BASE_LOGGING_H_
18#define ART_RUNTIME_BASE_LOGGING_H_
19
20#include <ostream>
21#include <sstream>
22
23#include "android-base/logging.h"
24#include "base/macros.h"
25
26namespace art {
27
28// Make libbase's LogSeverity more easily available.
29using LogSeverity = ::android::base::LogSeverity;
30using ScopedLogSeverity = ::android::base::ScopedLogSeverity;
31
32// The members of this struct are the valid arguments to VLOG and VLOG_IS_ON in code,
33// and the "-verbose:" command line argument.
34struct LogVerbosity {
35  bool class_linker;  // Enabled with "-verbose:class".
36  bool collector;
37  bool compiler;
38  bool deopt;
39  bool gc;
40  bool heap;
41  bool jdwp;
42  bool jit;
43  bool jni;
44  bool monitor;
45  bool oat;
46  bool profiler;
47  bool signals;
48  bool simulator;
49  bool startup;
50  bool third_party_jni;  // Enabled with "-verbose:third-party-jni".
51  bool threads;
52  bool verifier;
53  bool image;
54  bool systrace_lock_logging;  // Enabled with "-verbose:sys-locks".
55  bool agents;
56};
57
58// Global log verbosity setting, initialized by InitLogging.
59extern LogVerbosity gLogVerbosity;
60
61// 0 if not abort, non-zero if an abort is in progress. Used on fatal exit to prevents recursive
62// aborts. Global declaration allows us to disable some error checking to ensure fatal shutdown
63// makes forward progress.
64extern unsigned int gAborting;
65
66// Configure logging based on ANDROID_LOG_TAGS environment variable.
67// We need to parse a string that looks like
68//
69//      *:v jdwp:d dalvikvm:d dalvikvm-gc:i dalvikvmi:i
70//
71// The tag (or '*' for the global level) comes first, followed by a colon
72// and a letter indicating the minimum priority level we're expected to log.
73// This can be used to reveal or conceal logs with specific tags.
74extern void InitLogging(char* argv[]);
75
76// Returns the command line used to invoke the current tool or null if InitLogging hasn't been
77// performed.
78extern const char* GetCmdLine();
79
80// The command used to start the ART runtime, such as "/system/bin/dalvikvm". If InitLogging hasn't
81// been performed then just returns "art"
82extern const char* ProgramInvocationName();
83
84// A short version of the command used to start the ART runtime, such as "dalvikvm". If InitLogging
85// hasn't been performed then just returns "art"
86extern const char* ProgramInvocationShortName();
87
88class LogHelper {
89 public:
90  // A logging helper for logging a single line. Can be used with little stack.
91  static void LogLineLowStack(const char* file,
92                              unsigned int line,
93                              android::base::LogSeverity severity,
94                              const char* msg);
95
96 private:
97  DISALLOW_ALLOCATION();
98  DISALLOW_COPY_AND_ASSIGN(LogHelper);
99};
100
101// Is verbose logging enabled for the given module? Where the module is defined in LogVerbosity.
102#define VLOG_IS_ON(module) UNLIKELY(::art::gLogVerbosity.module)
103
104// Variant of LOG that logs when verbose logging is enabled for a module. For example,
105// VLOG(jni) << "A JNI operation was performed";
106#define VLOG(module) if (VLOG_IS_ON(module)) LOG(INFO)
107
108// Return the stream associated with logging for the given module.
109#define VLOG_STREAM(module) LOG_STREAM(INFO)
110
111}  // namespace art
112
113#endif  // ART_RUNTIME_BASE_LOGGING_H_
114