src/hotspot/share/logging/log.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 49621 5ef28d560b6f
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49621
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     4
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     7
 * published by the Free Software Foundation.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     8
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    13
 * accompanied this code).
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    14
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    18
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    21
 * questions.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    22
 *
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    23
 */
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49621
diff changeset
    24
#ifndef SHARE_LOGGING_LOG_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49621
diff changeset
    25
#define SHARE_LOGGING_LOG_HPP
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    26
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    27
#include "logging/logLevel.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    28
#include "logging/logPrefix.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    29
#include "logging/logTagSet.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    30
#include "logging/logTag.hpp"
33766
3290cae587f9 8138916: Logging write function does not allow for long enough messages
rprotacio
parents: 33097
diff changeset
    31
#include "runtime/os.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    32
#include "utilities/debug.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    33
38263
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37254
diff changeset
    34
class LogMessageBuffer;
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37254
diff changeset
    35
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    36
//
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    37
// Logging macros
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    38
//
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    39
// Usage:
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    40
//   log_<level>(<comma separated log tags>)(<printf-style log arguments>);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    41
// e.g.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    42
//   log_debug(logging)("message %d", i);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    43
//
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    44
// Note that these macros will not evaluate the arguments unless the logging is enabled.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    45
//
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    46
#define log_error(...)   (!log_is_enabled(Error, __VA_ARGS__))   ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Error>
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    47
#define log_warning(...) (!log_is_enabled(Warning, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Warning>
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    48
#define log_info(...)    (!log_is_enabled(Info, __VA_ARGS__))    ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Info>
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    49
#define log_debug(...)   (!log_is_enabled(Debug, __VA_ARGS__))   ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Debug>
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    50
#define log_trace(...)   (!log_is_enabled(Trace, __VA_ARGS__))   ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Trace>
34252
59d76c40998a 8143229: Replace the develop level with develop macros in Unified Logging
mlarsson
parents: 34251
diff changeset
    51
59d76c40998a 8143229: Replace the develop level with develop macros in Unified Logging
mlarsson
parents: 34251
diff changeset
    52
// Macros for logging that should be excluded in product builds.
59d76c40998a 8143229: Replace the develop level with develop macros in Unified Logging
mlarsson
parents: 34251
diff changeset
    53
// Available for levels Info, Debug and Trace. Includes test macro that
59d76c40998a 8143229: Replace the develop level with develop macros in Unified Logging
mlarsson
parents: 34251
diff changeset
    54
// evaluates to false in product builds.
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    55
#ifndef PRODUCT
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    56
#define log_develop_info(...)  (!log_is_enabled(Info, __VA_ARGS__))   ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Info>
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    57
#define log_develop_debug(...) (!log_is_enabled(Debug, __VA_ARGS__)) ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Debug>
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    58
#define log_develop_trace(...) (!log_is_enabled(Trace, __VA_ARGS__))  ? (void)0 : LogImpl<LOG_TAGS(__VA_ARGS__)>::write<LogLevel::Trace>
35901
f5028c67e7cb 8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents: 35897
diff changeset
    59
#define log_develop_is_enabled(level, ...)  log_is_enabled(level, __VA_ARGS__)
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    60
#else
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    61
#define DUMMY_ARGUMENT_CONSUMER(...)
34252
59d76c40998a 8143229: Replace the develop level with develop macros in Unified Logging
mlarsson
parents: 34251
diff changeset
    62
#define log_develop_info(...)  DUMMY_ARGUMENT_CONSUMER
59d76c40998a 8143229: Replace the develop level with develop macros in Unified Logging
mlarsson
parents: 34251
diff changeset
    63
#define log_develop_debug(...) DUMMY_ARGUMENT_CONSUMER
59d76c40998a 8143229: Replace the develop level with develop macros in Unified Logging
mlarsson
parents: 34251
diff changeset
    64
#define log_develop_trace(...) DUMMY_ARGUMENT_CONSUMER
35901
f5028c67e7cb 8147918: Rename develop_log_is_enabled() to log_develop_is_enabled()
pliden
parents: 35897
diff changeset
    65
#define log_develop_is_enabled(...)  false
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    66
#endif
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    67
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    68
// Convenience macro to test if the logging is enabled on the specified level for given tags.
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    69
#define log_is_enabled(level, ...) (LogImpl<LOG_TAGS(__VA_ARGS__)>::is_level(LogLevel::level))
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    70
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    71
//
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    72
// Log class for more advanced logging scenarios.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    73
// Has printf-style member functions for each log level (trace(), debug(), etc).
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    74
//
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    75
// Also has outputStream compatible API for the different log-levels.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    76
// The streams are resource allocated when requested and are accessed through
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    77
// calls to <level>_stream() functions (trace_stream(), debug_stream(), etc).
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    78
//
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    79
// Example usage:
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    80
//   Log(logging) log;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    81
//   if (log.is_debug()) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    82
//     ...
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    83
//     log.debug("result = %d", result).trace(" tracing info");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    84
//     obj->print_on(log.debug_stream());
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    85
//   }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    86
//
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
    87
#define Log(...)  LogImpl<LOG_TAGS(__VA_ARGS__)>
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    88
37245
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    89
//
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    90
// Log class that embeds both log tags and a log level.
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    91
//
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    92
// The class provides a way to write the tags and log level once,
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    93
// so that redundant specification of tags or levels can be avoided.
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    94
//
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    95
// Example usage:
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    96
//   LogTarget(Debug, gc) out;
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    97
//   if (out.is_enabled()) {
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    98
//     ...
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
    99
//     out.print("Worker: %u", i);
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   100
//     out.print(" data: %d", x);
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   101
//     ...
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   102
//     print_stats(out.stream());
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   103
//   }
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   104
//
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   105
#define LogTarget(level, ...) LogTargetImpl<LogLevel::level, LOG_TAGS(__VA_ARGS__)>
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   106
37254
8631304f255c 8152637: Create a stack allocatable LogStream class
stefank
parents: 37247
diff changeset
   107
template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
8631304f255c 8152637: Create a stack allocatable LogStream class
stefank
parents: 37247
diff changeset
   108
class LogTargetImpl;
8631304f255c 8152637: Create a stack allocatable LogStream class
stefank
parents: 37247
diff changeset
   109
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   110
template <LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG, LogTagType T3 = LogTag::__NO_TAG,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   111
          LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47216
diff changeset
   112
class LogImpl {
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   113
 private:
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   114
  static const size_t LogBufferSize = 512;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   115
 public:
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   116
  // Make sure no more than the maximum number of tags have been given.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   117
  // The GuardTag allows this to be detected if/when it happens. If the GuardTag
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   118
  // is not __NO_TAG, the number of tags given exceeds the maximum allowed.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   119
  STATIC_ASSERT(GuardTag == LogTag::__NO_TAG); // Number of logging tags exceeds maximum supported!
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   120
34251
0ce22a6d7d8c 8142483: Unified logging log instances cause warnings on windows when only static functions are used
mlarsson
parents: 33766
diff changeset
   121
  // Empty constructor to avoid warnings on MSVC about unused variables
0ce22a6d7d8c 8142483: Unified logging log instances cause warnings on windows when only static functions are used
mlarsson
parents: 33766
diff changeset
   122
  // when the log instance is only used for static functions.
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
   123
  LogImpl() {
34251
0ce22a6d7d8c 8142483: Unified logging log instances cause warnings on windows when only static functions are used
mlarsson
parents: 33766
diff changeset
   124
  }
0ce22a6d7d8c 8142483: Unified logging log instances cause warnings on windows when only static functions are used
mlarsson
parents: 33766
diff changeset
   125
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   126
  static bool is_level(LogLevelType level) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   127
    return LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().is_level(level);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   128
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   129
36573
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   130
  ATTRIBUTE_PRINTF(2, 3)
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   131
  static void write(LogLevelType level, const char* fmt, ...) {
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   132
    va_list args;
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   133
    va_start(args, fmt);
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   134
    vwrite(level, fmt, args);
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   135
    va_end(args);
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37245
diff changeset
   136
  }
36573
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   137
38263
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37254
diff changeset
   138
  static void write(const LogMessageBuffer& msg) {
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37254
diff changeset
   139
    LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().log(msg);
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37254
diff changeset
   140
  };
a7488329ad27 8145934: Make ttyLocker equivalent for Unified Logging framework
mlarsson
parents: 37254
diff changeset
   141
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   142
  template <LogLevelType Level>
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   143
  ATTRIBUTE_PRINTF(1, 2)
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   144
  static void write(const char* fmt, ...) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   145
    va_list args;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   146
    va_start(args, fmt);
36573
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   147
    vwrite(Level, fmt, args);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   148
    va_end(args);
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37245
diff changeset
   149
  }
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   150
36573
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   151
  ATTRIBUTE_PRINTF(2, 0)
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   152
  static void vwrite(LogLevelType level, const char* fmt, va_list args) {
37247
bdbfe42632cb 8153254: Delegate (v)write from Log to LogTagSet
rehn
parents: 37245
diff changeset
   153
    LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().vwrite(level, fmt, args);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   154
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   155
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   156
#define LOG_LEVEL(level, name) ATTRIBUTE_PRINTF(2, 0) \
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
   157
  LogImpl& v##name(const char* fmt, va_list args) { \
36573
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   158
    vwrite(LogLevel::level, fmt, args); \
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   159
    return *this; \
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   160
  } \
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37201
diff changeset
   161
  LogImpl& name(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3) { \
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   162
    va_list args; \
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   163
    va_start(args, fmt); \
36573
676134627feb 8150026: Add the ability to log with variable log level
rehn
parents: 35901
diff changeset
   164
    vwrite(LogLevel::level, fmt, args); \
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   165
    va_end(args); \
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   166
    return *this; \
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   167
  } \
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   168
  static bool is_##name() { \
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   169
    return is_level(LogLevel::level); \
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   170
  } \
37254
8631304f255c 8152637: Create a stack allocatable LogStream class
stefank
parents: 37247
diff changeset
   171
  static LogTargetImpl<LogLevel::level, T0, T1, T2, T3, T4, GuardTag>* name() { \
8631304f255c 8152637: Create a stack allocatable LogStream class
stefank
parents: 37247
diff changeset
   172
    return (LogTargetImpl<LogLevel::level, T0, T1, T2, T3, T4, GuardTag>*)NULL; \
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   173
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   174
  LOG_LEVEL_LIST
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   175
#undef LOG_LEVEL
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   176
};
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   177
37245
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   178
// Combines logging tags and a logging level.
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   179
template <LogLevelType level, LogTagType T0, LogTagType T1 = LogTag::__NO_TAG, LogTagType T2 = LogTag::__NO_TAG,
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   180
          LogTagType T3 = LogTag::__NO_TAG, LogTagType T4 = LogTag::__NO_TAG, LogTagType GuardTag = LogTag::__NO_TAG>
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   181
class LogTargetImpl {
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   182
public:
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   183
  // Empty constructor to avoid warnings on MSVC about unused variables
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   184
  // when the log instance is only used for static functions.
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   185
  LogTargetImpl() {
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   186
  }
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   187
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   188
  static bool is_enabled() {
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   189
    return LogImpl<T0, T1, T2, T3, T4, GuardTag>::is_level(level);
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   190
  }
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   191
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   192
  static void print(const char* fmt, ...) ATTRIBUTE_PRINTF(1, 2) {
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   193
    va_list args;
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   194
    va_start(args, fmt);
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   195
    LogImpl<T0, T1, T2, T3, T4, GuardTag>::vwrite(level, fmt, args);
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   196
    va_end(args);
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   197
  }
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   198
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   199
};
70413a0266d4 8152635: Create a UL class to represent a Log + Level combination
stefank
parents: 37242
diff changeset
   200
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49621
diff changeset
   201
#endif // SHARE_LOGGING_LOG_HPP