Home | History | Annotate | Download | only in base
      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_LIBARTBASE_BASE_LOGGING_H_
     18 #define ART_LIBARTBASE_BASE_LOGGING_H_
     19 
     20 #include <ostream>
     21 #include <sstream>
     22 
     23 #include "android-base/logging.h"
     24 #include "base/macros.h"
     25 
     26 namespace art {
     27 
     28 // Make libbase's LogSeverity more easily available.
     29 using ::android::base::LogSeverity;
     30 using ::android::base::ScopedLogSeverity;
     31 
     32 // Abort function.
     33 using AbortFunction = void(const char*);
     34 
     35 // The members of this struct are the valid arguments to VLOG and VLOG_IS_ON in code,
     36 // and the "-verbose:" command line argument.
     37 struct LogVerbosity {
     38   bool class_linker;  // Enabled with "-verbose:class".
     39   bool collector;
     40   bool compiler;
     41   bool deopt;
     42   bool gc;
     43   bool heap;
     44   bool jdwp;
     45   bool jit;
     46   bool jni;
     47   bool monitor;
     48   bool oat;
     49   bool profiler;
     50   bool signals;
     51   bool simulator;
     52   bool startup;
     53   bool third_party_jni;  // Enabled with "-verbose:third-party-jni".
     54   bool threads;
     55   bool verifier;
     56   bool verifier_debug;   // Only works in debug builds.
     57   bool image;
     58   bool systrace_lock_logging;  // Enabled with "-verbose:sys-locks".
     59   bool agents;
     60   bool dex;  // Some dex access output etc.
     61 };
     62 
     63 // Global log verbosity setting, initialized by InitLogging.
     64 extern LogVerbosity gLogVerbosity;
     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.
     74 extern void InitLogging(char* argv[], AbortFunction& default_aborter);
     75 
     76 // Returns the command line used to invoke the current tool or null if InitLogging hasn't been
     77 // performed.
     78 extern 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"
     82 extern 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"
     86 extern const char* ProgramInvocationShortName();
     87 
     88 class 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_LIBARTBASE_BASE_LOGGING_H_
    114