src/hotspot/share/logging/logConfiguration.cpp
author mlarsson
Mon, 19 Feb 2018 09:16:04 +0100
changeset 49015 a12c9536d8a6
parent 48824 e48c4461a8bb
child 49016 ea85eed8b012
permissions -rw-r--r--
8176298: Log tags in -Xlog:help not sorted Reviewed-by: ecaspole, gtriantafill, stuefe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     1
/*
49015
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 48824
diff changeset
     2
 * Copyright (c) 2015, 2018, 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
 */
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    24
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    25
#include "jvm.h"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    26
#include "logging/log.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    27
#include "logging/logConfiguration.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    28
#include "logging/logDecorations.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    29
#include "logging/logDecorators.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    30
#include "logging/logDiagnosticCommand.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    31
#include "logging/logFileOutput.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    32
#include "logging/logOutput.hpp"
38292
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    33
#include "logging/logStream.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    34
#include "logging/logTagLevelExpression.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    35
#include "logging/logTagSet.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    36
#include "memory/allocation.inline.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    37
#include "memory/resourceArea.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    38
#include "runtime/os.inline.hpp"
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    39
#include "runtime/semaphore.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    40
#include "utilities/globalDefinitions.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    41
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    42
LogOutput** LogConfiguration::_outputs = NULL;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    43
size_t      LogConfiguration::_n_outputs = 0;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    44
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
    45
LogConfiguration::UpdateListenerFunction* LogConfiguration::_listener_callbacks = NULL;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
    46
size_t      LogConfiguration::_n_listener_callbacks = 0;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
    47
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
    48
// LogFileOutput is the default type of output, its type prefix should be used if no type was specified
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
    49
static const char* implicit_output_prefix = LogFileOutput::Prefix;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
    50
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    51
// Stack object to take the lock for configuring the logging.
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    52
// Should only be held during the critical parts of the configuration
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    53
// (when calling configure_output or reading/modifying the outputs array).
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    54
// Thread must never block when holding this lock.
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    55
class ConfigurationLock : public StackObj {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    56
 private:
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    57
  // Semaphore used as lock
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    58
  static Semaphore _semaphore;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    59
  debug_only(static intx _locking_thread_id;)
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    60
 public:
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    61
  ConfigurationLock() {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    62
    _semaphore.wait();
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    63
    debug_only(_locking_thread_id = os::current_thread_id());
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    64
  }
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    65
  ~ConfigurationLock() {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    66
    debug_only(_locking_thread_id = -1);
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    67
    _semaphore.signal();
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    68
  }
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    69
  debug_only(static bool current_thread_has_lock();)
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    70
};
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    71
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    72
Semaphore ConfigurationLock::_semaphore(1);
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    73
#ifdef ASSERT
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    74
intx ConfigurationLock::_locking_thread_id = -1;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    75
bool ConfigurationLock::current_thread_has_lock() {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    76
  return _locking_thread_id == os::current_thread_id();
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    77
}
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    78
#endif
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    79
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    80
void LogConfiguration::post_initialize() {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    81
  LogDiagnosticCommand::registerCommand();
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37108
diff changeset
    82
  Log(logging) log;
38292
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    83
  if (log.is_info()) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    84
    log.info("Log configuration fully initialized.");
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    85
    log_develop_info(logging)("Develop logging is available.");
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    86
    if (log.is_debug()) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    87
      LogStream debug_stream(log.debug());
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    88
      describe(&debug_stream);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    89
      if (log.is_trace()) {
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    90
        LogStream trace_stream(log.trace());
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    91
        LogTagSet::list_all_tagsets(&trace_stream);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    92
      }
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
    93
    }
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    94
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    95
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    96
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    97
void LogConfiguration::initialize(jlong vm_start_time) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    98
  LogFileOutput::set_file_name_parameters(vm_start_time);
36174
481391df586b 8148219: Add decorator hostname to UL
mlarsson
parents: 35230
diff changeset
    99
  LogDecorations::initialize(vm_start_time);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   100
  assert(_outputs == NULL, "Should not initialize _outputs before this function, initialize called twice?");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   101
  _outputs = NEW_C_HEAP_ARRAY(LogOutput*, 2, mtLogging);
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 40924
diff changeset
   102
  _outputs[0] = &StdoutLog;
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 40924
diff changeset
   103
  _outputs[1] = &StderrLog;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   104
  _n_outputs = 2;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   105
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   106
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   107
void LogConfiguration::finalize() {
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 40924
diff changeset
   108
  for (size_t i = _n_outputs; i > 0; i--) {
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 40924
diff changeset
   109
    disable_output(i - 1);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   110
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   111
  FREE_C_HEAP_ARRAY(LogOutput*, _outputs);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   112
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   113
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   114
// Normalizes the given LogOutput name to type=name form.
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   115
// For example, foo, "foo", file="foo", will all be normalized to file=foo (no quotes, prefixed).
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   116
static bool normalize_output_name(const char* full_name, char* buffer, size_t len, outputStream* errstream) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   117
  const char* start_quote = strchr(full_name, '"');
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   118
  const char* equals = strchr(full_name, '=');
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   119
  const bool quoted = start_quote != NULL;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   120
  const bool is_stdout_or_stderr = (strcmp(full_name, "stdout") == 0 || strcmp(full_name, "stderr") == 0);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   121
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   122
  // ignore equals sign within quotes
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   123
  if (quoted && equals > start_quote) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   124
    equals = NULL;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   125
  }
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   126
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   127
  const char* prefix = "";
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   128
  size_t prefix_len = 0;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   129
  const char* name = full_name;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   130
  if (equals != NULL) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   131
    // split on equals sign
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   132
    name = equals + 1;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   133
    prefix = full_name;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   134
    prefix_len = equals - full_name + 1;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   135
  } else if (!is_stdout_or_stderr) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   136
    prefix = implicit_output_prefix;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   137
    prefix_len = strlen(prefix);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   138
  }
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   139
  size_t name_len = strlen(name);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   140
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   141
  if (quoted) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   142
    const char* end_quote = strchr(start_quote + 1, '"');
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   143
    if (end_quote == NULL) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   144
      errstream->print_cr("Output name has opening quote but is missing a terminating quote.");
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   145
      return false;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   146
    }
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   147
    if (start_quote != name || end_quote[1] != '\0') {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   148
      errstream->print_cr("Output name can not be partially quoted."
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   149
                          " Either surround the whole name with quotation marks,"
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   150
                          " or do not use quotation marks at all.");
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   151
      return false;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   152
    }
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   153
    // strip start and end quote
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   154
    name++;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   155
    name_len -= 2;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   156
  }
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   157
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   158
  int ret = jio_snprintf(buffer, len, "%.*s%.*s", prefix_len, prefix, name_len, name);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   159
  assert(ret > 0, "buffer issue");
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   160
  return true;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   161
}
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   162
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   163
size_t LogConfiguration::find_output(const char* name) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   164
  for (size_t i = 0; i < _n_outputs; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   165
    if (strcmp(_outputs[i]->name(), name) == 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   166
      return i;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   167
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   168
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   169
  return SIZE_MAX;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   170
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   171
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   172
LogOutput* LogConfiguration::new_output(const char* name,
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   173
                                        const char* options,
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   174
                                        outputStream* errstream) {
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   175
  LogOutput* output;
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   176
  if (strncmp(name, LogFileOutput::Prefix, strlen(LogFileOutput::Prefix)) == 0) {
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   177
    output = new LogFileOutput(name);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   178
  } else {
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   179
    errstream->print_cr("Unsupported log output type: %s", name);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   180
    return NULL;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   181
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   182
37465
1d5551f466ee 8146879: Add option for handling existing log files in UL
mlarsson
parents: 37242
diff changeset
   183
  bool success = output->initialize(options, errstream);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   184
  if (!success) {
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   185
    errstream->print_cr("Initialization of output '%s' using options '%s' failed.", name, options);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   186
    delete output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   187
    return NULL;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   188
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   189
  return output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   190
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   191
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   192
size_t LogConfiguration::add_output(LogOutput* output) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   193
  size_t idx = _n_outputs++;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   194
  _outputs = REALLOC_C_HEAP_ARRAY(LogOutput*, _outputs, _n_outputs, mtLogging);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   195
  _outputs[idx] = output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   196
  return idx;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   197
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   198
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   199
void LogConfiguration::delete_output(size_t idx) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   200
  assert(idx > 1 && idx < _n_outputs,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33097
diff changeset
   201
         "idx must be in range 1 < idx < _n_outputs, but idx = " SIZE_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33097
diff changeset
   202
         " and _n_outputs = " SIZE_FORMAT, idx, _n_outputs);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   203
  LogOutput* output = _outputs[idx];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   204
  // Swap places with the last output and shrink the array
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   205
  _outputs[idx] = _outputs[--_n_outputs];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   206
  _outputs = REALLOC_C_HEAP_ARRAY(LogOutput*, _outputs, _n_outputs, mtLogging);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   207
  delete output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   208
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   209
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   210
void LogConfiguration::configure_output(size_t idx, const LogTagLevelExpression& tag_level_expression, const LogDecorators& decorators) {
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   211
  assert(ConfigurationLock::current_thread_has_lock(), "Must hold configuration lock to call this function.");
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33097
diff changeset
   212
  assert(idx < _n_outputs, "Invalid index, idx = " SIZE_FORMAT " and _n_outputs = " SIZE_FORMAT, idx, _n_outputs);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   213
  LogOutput* output = _outputs[idx];
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   214
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   215
  // Clear the previous config description
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   216
  output->clear_config_string();
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   217
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   218
  bool enabled = false;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   219
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   220
    LogLevelType level = tag_level_expression.level_for(*ts);
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   221
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   222
    // Ignore tagsets that do not, and will not log on the output
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   223
    if (!ts->has_output(output) && (level == LogLevel::NotMentioned || level == LogLevel::Off)) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   224
      continue;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   225
    }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   226
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   227
    // Update decorators before adding/updating output level,
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   228
    // so that the tagset will have the necessary decorators when requiring them.
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   229
    if (level != LogLevel::Off) {
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   230
      ts->update_decorators(decorators);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   231
    }
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   232
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   233
    // Set the new level, if it changed
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   234
    if (level != LogLevel::NotMentioned) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   235
      ts->set_output_level(output, level);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   236
    }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   237
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   238
    if (level != LogLevel::Off) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   239
      // Keep track of whether or not the output is ever used by some tagset
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   240
      enabled = true;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   241
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   242
      if (level == LogLevel::NotMentioned) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   243
        // Look up the previously set level for this output on this tagset
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   244
        level = ts->level_for(output);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   245
      }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   246
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   247
      // Update the config description with this tagset and level
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   248
      output->add_to_config_string(ts, level);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   249
    }
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   250
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   251
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   252
  // It is now safe to set the new decorators for the actual output
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   253
  output->set_decorators(decorators);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   254
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   255
  // Update the decorators on all tagsets to get rid of unused decorators
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   256
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   257
    ts->update_decorators();
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   258
  }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   259
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   260
  if (enabled) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   261
    assert(strlen(output->config_string()) > 0,
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   262
           "Should always have a config description if the output is enabled.");
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   263
  } else if (idx > 1) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   264
    // Output is unused and should be removed.
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   265
    delete_output(idx);
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   266
  } else {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   267
    // Output is either stdout or stderr, which means we can't remove it.
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   268
    // Update the config description to reflect that the output is disabled.
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   269
    output->set_config_string("all=off");
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   270
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   271
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   272
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   273
void LogConfiguration::disable_output(size_t idx) {
40885
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   274
  assert(idx < _n_outputs, "invalid index: " SIZE_FORMAT " (_n_outputs: " SIZE_FORMAT ")", idx, _n_outputs);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   275
  LogOutput* out = _outputs[idx];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   276
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   277
  // Remove the output from all tagsets.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   278
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   279
    ts->set_output_level(out, LogLevel::Off);
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   280
    ts->update_decorators();
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   281
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   282
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 40924
diff changeset
   283
  // Delete the output unless stdout or stderr (idx 0 or 1)
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 40924
diff changeset
   284
  if (idx > 1) {
40885
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   285
    delete_output(idx);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   286
  } else {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   287
    out->set_config_string("all=off");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   288
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   289
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   290
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   291
void LogConfiguration::disable_logging() {
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   292
  ConfigurationLock cl;
40885
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   293
  for (size_t i = _n_outputs; i > 0; i--) {
b3958b331451 8150823: UL disables log outputs incorrectly
mlarsson
parents: 40884
diff changeset
   294
    disable_output(i - 1);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   295
  }
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   296
  notify_update_listeners();
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   297
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   298
48824
e48c4461a8bb 8181503: Can't compile hotspot with c++11
gziemski
parents: 47765
diff changeset
   299
void LogConfiguration::configure_stdout(LogLevelType level, int exact_match, ...) {
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   300
  size_t i;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   301
  va_list ap;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   302
  LogTagLevelExpression expr;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   303
  va_start(ap, exact_match);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   304
  for (i = 0; i < LogTag::MaxTags; i++) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   305
    LogTagType tag = static_cast<LogTagType>(va_arg(ap, int));
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   306
    expr.add_tag(tag);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   307
    if (tag == LogTag::__NO_TAG) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   308
      assert(i > 0, "Must specify at least one tag!");
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   309
      break;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   310
    }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   311
  }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   312
  assert(i < LogTag::MaxTags || static_cast<LogTagType>(va_arg(ap, int)) == LogTag::__NO_TAG,
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   313
         "Too many tags specified! Can only have up to " SIZE_FORMAT " tags in a tag set.", LogTag::MaxTags);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   314
  va_end(ap);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   315
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   316
  if (!exact_match) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   317
    expr.set_allow_other_tags();
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   318
  }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   319
  expr.set_level(level);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   320
  expr.new_combination();
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   321
  assert(expr.verify_tagsets(),
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   322
         "configure_stdout() called with invalid/non-existing tag set");
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   323
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   324
  // Apply configuration to stdout (output #0), with the same decorators as before.
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   325
  ConfigurationLock cl;
42067
34b99c8faa51 8146009: "pure virtual method called" with using new GC logging mechanism
mlarsson
parents: 40924
diff changeset
   326
  configure_output(0, expr, _outputs[0]->decorators());
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   327
  notify_update_listeners();
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   328
}
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   329
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   330
bool LogConfiguration::parse_command_line_arguments(const char* opts) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   331
  char* copy = os::strdup_check_oom(opts, mtLogging);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   332
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   333
  // Split the option string to its colon separated components.
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   334
  char* str = copy;
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   335
  char* substrings[4] = {0};
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   336
  for (int i = 0 ; i < 4; i++) {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   337
    substrings[i] = str;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   338
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   339
    // Find the next colon or quote
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   340
    char* next = strpbrk(str, ":\"");
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   341
    while (next != NULL && *next == '"') {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   342
      char* end_quote = strchr(next + 1, '"');
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   343
      if (end_quote == NULL) {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   344
        log_error(logging)("Missing terminating quote in -Xlog option '%s'", str);
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   345
        os::free(copy);
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   346
        return false;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   347
      }
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   348
      // Keep searching after the quoted substring
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   349
      next = strpbrk(end_quote + 1, ":\"");
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   350
    }
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   351
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   352
    if (next != NULL) {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   353
      *next = '\0';
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   354
      str = next + 1;
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   355
    } else {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   356
      break;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   357
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   358
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   359
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   360
  // Parse and apply the separated configuration options
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   361
  char* what = substrings[0];
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   362
  char* output = substrings[1];
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   363
  char* decorators = substrings[2];
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   364
  char* output_options = substrings[3];
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   365
  char errbuf[512];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   366
  stringStream ss(errbuf, sizeof(errbuf));
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   367
  bool success = parse_log_arguments(output, what, decorators, output_options, &ss);
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   368
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   369
  if (ss.size() > 0) {
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   370
    errbuf[strlen(errbuf) - 1] = '\0'; // Strip trailing newline
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   371
    // If it failed, log the error. If it didn't fail, but something was written
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   372
    // to the stream, log it as a warning.
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   373
    if (!success) {
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   374
      log_error(logging)("%s", ss.base());
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   375
    } else {
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   376
      log_warning(logging)("%s", ss.base());
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   377
    }
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   378
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   379
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   380
  os::free(copy);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   381
  return success;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   382
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   383
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   384
bool LogConfiguration::parse_log_arguments(const char* outputstr,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   385
                                           const char* what,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   386
                                           const char* decoratorstr,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   387
                                           const char* output_options,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   388
                                           outputStream* errstream) {
40924
226073476e18 8165226: Bad -Xloggc: arguments crashes the VM
mlarsson
parents: 40902
diff changeset
   389
  assert(errstream != NULL, "errstream can not be NULL");
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   390
  if (outputstr == NULL || strlen(outputstr) == 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   391
    outputstr = "stdout";
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   392
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   393
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   394
  LogTagLevelExpression expr;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   395
  if (!expr.parse(what, errstream)) {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   396
    return false;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   397
  }
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   398
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   399
  LogDecorators decorators;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   400
  if (!decorators.parse(decoratorstr, errstream)) {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   401
    return false;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   402
  }
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   403
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   404
  ConfigurationLock cl;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   405
  size_t idx;
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   406
  if (outputstr[0] == '#') { // Output specified using index
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   407
    int ret = sscanf(outputstr + 1, SIZE_FORMAT, &idx);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   408
    if (ret != 1 || idx >= _n_outputs) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   409
      errstream->print_cr("Invalid output index '%s'", outputstr);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   410
      return false;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   411
    }
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   412
  } else { // Output specified using name
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   413
    // Normalize the name, stripping quotes and ensures it includes type prefix
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   414
    size_t len = strlen(outputstr) + strlen(implicit_output_prefix) + 1;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   415
    char* normalized = NEW_C_HEAP_ARRAY(char, len, mtLogging);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   416
    if (!normalize_output_name(outputstr, normalized, len, errstream)) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   417
      return false;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   418
    }
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   419
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   420
    idx = find_output(normalized);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   421
    if (idx == SIZE_MAX) {
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   422
      // Attempt to create and add the output
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   423
      LogOutput* output = new_output(normalized, output_options, errstream);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   424
      if (output != NULL) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   425
        idx = add_output(output);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   426
      }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   427
    } else if (output_options != NULL && strlen(output_options) > 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   428
      errstream->print_cr("Output options for existing outputs are ignored.");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   429
    }
40902
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   430
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   431
    FREE_C_HEAP_ARRAY(char, normalized);
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   432
    if (idx == SIZE_MAX) {
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   433
      return false;
395e1f3ec886 8157948: UL allows same log file with multiple file=
mlarsson
parents: 40885
diff changeset
   434
    }
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   435
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   436
  configure_output(idx, expr, decorators);
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   437
  notify_update_listeners();
40884
0e28c526f5d3 8150894: Unused -Xlog tag sequences are silently ignored.
mlarsson
parents: 39707
diff changeset
   438
  expr.verify_tagsets(errstream);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   439
  return true;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   440
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   441
37994
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   442
void LogConfiguration::describe_available(outputStream* out){
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   443
  out->print("Available log levels:");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   444
  for (size_t i = 0; i < LogLevel::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   445
    out->print("%s %s", (i == 0 ? "" : ","), LogLevel::name(static_cast<LogLevelType>(i)));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   446
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   447
  out->cr();
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   448
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   449
  out->print("Available log decorators:");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   450
  for (size_t i = 0; i < LogDecorators::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   451
    LogDecorators::Decorator d = static_cast<LogDecorators::Decorator>(i);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   452
    out->print("%s %s (%s)", (i == 0 ? "" : ","), LogDecorators::name(d), LogDecorators::abbreviation(d));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   453
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   454
  out->cr();
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   455
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   456
  out->print("Available log tags:");
49015
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 48824
diff changeset
   457
  LogTag::list_tags(out);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   458
38292
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
   459
  LogTagSet::describe_tagsets(out);
37994
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   460
}
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   461
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   462
void LogConfiguration::describe_current_configuration(outputStream* out){
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   463
  out->print_cr("Log output configuration:");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   464
  for (size_t i = 0; i < _n_outputs; i++) {
39707
4974c8df2532 8153074: UL: Show output option in VM.log jcmd
ysuenaga
parents: 39286
diff changeset
   465
    out->print("#" SIZE_FORMAT ": ", i);
4974c8df2532 8153074: UL: Show output option in VM.log jcmd
ysuenaga
parents: 39286
diff changeset
   466
    _outputs[i]->describe(out);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   467
    out->cr();
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   468
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   469
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   470
37994
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   471
void LogConfiguration::describe(outputStream* out) {
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   472
  describe_available(out);
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   473
  ConfigurationLock cl;
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   474
  describe_current_configuration(out);
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   475
}
1a816b464178 8151526: Print -Xlog configuration in the hs_err_pid file
mockner
parents: 37465
diff changeset
   476
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   477
void LogConfiguration::print_command_line_help(FILE* out) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   478
  jio_fprintf(out, "-Xlog Usage: -Xlog[:[what][:[output][:[decorators][:output-options]]]]\n"
43418
1219e26448f1 8170857: Typo in -Xlog:help output
mlarsson
parents: 43417
diff changeset
   479
              "\t where 'what' is a combination of tags and levels of the form tag1[+tag2...][*][=level][,...]\n"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   480
              "\t Unless wildcard (*) is specified, only log messages tagged with exactly the tags specified will be matched.\n\n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   481
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   482
  jio_fprintf(out, "Available log levels:\n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   483
  for (size_t i = 0; i < LogLevel::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   484
    jio_fprintf(out, "%s %s", (i == 0 ? "" : ","), LogLevel::name(static_cast<LogLevelType>(i)));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   485
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   486
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   487
  jio_fprintf(out, "\n\nAvailable log decorators: \n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   488
  for (size_t i = 0; i < LogDecorators::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   489
    LogDecorators::Decorator d = static_cast<LogDecorators::Decorator>(i);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   490
    jio_fprintf(out, "%s %s (%s)", (i == 0 ? "" : ","), LogDecorators::name(d), LogDecorators::abbreviation(d));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   491
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   492
  jio_fprintf(out, "\n Decorators can also be specified as 'none' for no decoration.\n\n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   493
49015
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 48824
diff changeset
   494
  fileStream stream(out, false);
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 48824
diff changeset
   495
  stream.print_cr("Available log tags:");
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 48824
diff changeset
   496
  LogTag::list_tags(&stream);
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 48824
diff changeset
   497
  stream.print_cr(" Specifying 'all' instead of a tag combination matches all tag combinations.");
a12c9536d8a6 8176298: Log tags in -Xlog:help not sorted
mlarsson
parents: 48824
diff changeset
   498
  stream.cr();
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   499
38292
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
   500
  LogTagSet::describe_tagsets(&stream);
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
   501
73a0be9b2f47 8146948: Enable listing of LogTagSets and add support for LogTagSet descriptions
mlarsson
parents: 38195
diff changeset
   502
  jio_fprintf(out, "\nAvailable log outputs:\n"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   503
              " stdout, stderr, file=<filename>\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   504
              " Specifying %%p and/or %%t in the filename will expand to the JVM's PID and startup timestamp, respectively.\n\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   505
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   506
              "Some examples:\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   507
              " -Xlog\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   508
              "\t Log all messages using 'info' level to stdout with 'uptime', 'levels' and 'tags' decorations.\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   509
              "\t (Equivalent to -Xlog:all=info:stdout:uptime,levels,tags).\n\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   510
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   511
              " -Xlog:gc\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   512
              "\t Log messages tagged with 'gc' tag using 'info' level to stdout, with default decorations.\n\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   513
43417
90c1f522d37e 8170855: Example for -Xlog:help do not contain one with multiple tags
mlarsson
parents: 42067
diff changeset
   514
              " -Xlog:gc,safepoint\n"
90c1f522d37e 8170855: Example for -Xlog:help do not contain one with multiple tags
mlarsson
parents: 42067
diff changeset
   515
              "\t Log messages tagged either with 'gc' or 'safepoint' tags, both using 'info' level, to stdout, with default decorations.\n"
90c1f522d37e 8170855: Example for -Xlog:help do not contain one with multiple tags
mlarsson
parents: 42067
diff changeset
   516
              "\t (Messages tagged with both 'gc' and 'safepoint' will not be logged.)\n\n"
90c1f522d37e 8170855: Example for -Xlog:help do not contain one with multiple tags
mlarsson
parents: 42067
diff changeset
   517
90c1f522d37e 8170855: Example for -Xlog:help do not contain one with multiple tags
mlarsson
parents: 42067
diff changeset
   518
              " -Xlog:gc+ref=debug\n"
90c1f522d37e 8170855: Example for -Xlog:help do not contain one with multiple tags
mlarsson
parents: 42067
diff changeset
   519
              "\t Log messages tagged with both 'gc' and 'ref' tags, using 'debug' level, to stdout, with default decorations.\n"
90c1f522d37e 8170855: Example for -Xlog:help do not contain one with multiple tags
mlarsson
parents: 42067
diff changeset
   520
              "\t (Messages tagged only with one of the two tags will not be logged.)\n\n"
90c1f522d37e 8170855: Example for -Xlog:help do not contain one with multiple tags
mlarsson
parents: 42067
diff changeset
   521
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   522
              " -Xlog:gc=debug:file=gc.txt:none\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   523
              "\t Log messages tagged with 'gc' tag using 'debug' level to file 'gc.txt' with no decorations.\n\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   524
38195
d317aafcc87c 8153073: UL: Set filesize option with k/m/g
ysuenaga
parents: 38124
diff changeset
   525
              " -Xlog:gc=trace:file=gctrace.txt:uptimemillis,pids:filecount=5,filesize=1m\n"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   526
              "\t Log messages tagged with 'gc' tag using 'trace' level to a rotating fileset of 5 files of size 1MB,\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   527
              "\t using the base name 'gctrace.txt', with 'uptimemillis' and 'pid' decorations.\n\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   528
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   529
              " -Xlog:gc::uptime,tid\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   530
              "\t Log messages tagged with 'gc' tag using 'info' level to output 'stdout', using 'uptime' and 'tid' decorations.\n\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   531
39286
0613bf956db4 8154106: UL Xlog:help regd'g 'rt' tag
rehn
parents: 38729
diff changeset
   532
              " -Xlog:gc*=info,safepoint*=off\n"
0613bf956db4 8154106: UL Xlog:help regd'g 'rt' tag
rehn
parents: 38729
diff changeset
   533
              "\t Log messages tagged with at least 'gc' using 'info' level, but turn off logging of messages tagged with 'safepoint'.\n"
0613bf956db4 8154106: UL Xlog:help regd'g 'rt' tag
rehn
parents: 38729
diff changeset
   534
              "\t (Messages tagged with both 'gc' and 'safepoint' will not be logged.)\n\n"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   535
39286
0613bf956db4 8154106: UL Xlog:help regd'g 'rt' tag
rehn
parents: 38729
diff changeset
   536
              " -Xlog:disable -Xlog:safepoint=trace:safepointtrace.txt\n"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   537
              "\t Turn off all logging, including warnings and errors,\n"
39286
0613bf956db4 8154106: UL Xlog:help regd'g 'rt' tag
rehn
parents: 38729
diff changeset
   538
              "\t and then enable messages tagged with 'safepoint' using 'trace' level to file 'safepointtrace.txt'.\n");
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   539
}
34637
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   540
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   541
void LogConfiguration::rotate_all_outputs() {
35230
a528ea8203ec 8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents: 35229
diff changeset
   542
  // Start from index 2 since neither stdout nor stderr can be rotated.
a528ea8203ec 8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents: 35229
diff changeset
   543
  for (size_t idx = 2; idx < _n_outputs; idx++) {
a528ea8203ec 8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents: 35229
diff changeset
   544
    _outputs[idx]->force_rotate();
34637
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   545
  }
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   546
}
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   547
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   548
void LogConfiguration::register_update_listener(UpdateListenerFunction cb) {
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   549
  assert(cb != NULL, "Should not register NULL as listener");
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   550
  ConfigurationLock cl;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   551
  size_t idx = _n_listener_callbacks++;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   552
  _listener_callbacks = REALLOC_C_HEAP_ARRAY(UpdateListenerFunction,
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   553
                                             _listener_callbacks,
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   554
                                             _n_listener_callbacks,
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   555
                                             mtLogging);
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   556
  _listener_callbacks[idx] = cb;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   557
}
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   558
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   559
void LogConfiguration::notify_update_listeners() {
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   560
  assert(ConfigurationLock::current_thread_has_lock(), "notify_update_listeners must be called in ConfigurationLock scope (lock held)");
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   561
  for (size_t i = 0; i < _n_listener_callbacks; i++) {
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   562
    _listener_callbacks[i]();
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   563
  }
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   564
}