hotspot/src/share/vm/logging/logConfiguration.cpp
author mlarsson
Mon, 11 Apr 2016 12:22:09 +0200
changeset 37465 1d5551f466ee
parent 37242 91e5f98fff6f
child 37994 1a816b464178
permissions -rw-r--r--
8146879: Add option for handling existing log files in UL Reviewed-by: dsamersoff, gziemski, rehn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     1
/*
36174
481391df586b 8148219: Add decorator hostname to UL
mlarsson
parents: 35230
diff changeset
     2
 * Copyright (c) 2015, 2016, 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"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    25
#include "logging/log.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    26
#include "logging/logConfiguration.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    27
#include "logging/logDecorations.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    28
#include "logging/logDecorators.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    29
#include "logging/logDiagnosticCommand.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    30
#include "logging/logFileOutput.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    31
#include "logging/logOutput.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    32
#include "logging/logTagLevelExpression.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    33
#include "logging/logTagSet.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    34
#include "memory/allocation.inline.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    35
#include "memory/resourceArea.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    36
#include "runtime/os.inline.hpp"
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    37
#include "runtime/semaphore.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    38
#include "utilities/globalDefinitions.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    39
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    40
LogOutput** LogConfiguration::_outputs = NULL;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    41
size_t      LogConfiguration::_n_outputs = 0;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    42
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
    43
LogConfiguration::UpdateListenerFunction* LogConfiguration::_listener_callbacks = NULL;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
    44
size_t      LogConfiguration::_n_listener_callbacks = 0;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
    45
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    46
// 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
    47
// 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
    48
// (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
    49
// 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
    50
class ConfigurationLock : public StackObj {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    51
 private:
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    52
  // Semaphore used as lock
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    53
  static Semaphore _semaphore;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    54
  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
    55
 public:
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    56
  ConfigurationLock() {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    57
    _semaphore.wait();
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    58
    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
    59
  }
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    60
  ~ConfigurationLock() {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    61
    debug_only(_locking_thread_id = -1);
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    62
    _semaphore.signal();
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    63
  }
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    64
  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
    65
};
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    66
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    67
Semaphore ConfigurationLock::_semaphore(1);
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    68
#ifdef ASSERT
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    69
intx ConfigurationLock::_locking_thread_id = -1;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    70
bool ConfigurationLock::current_thread_has_lock() {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    71
  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
    72
}
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    73
#endif
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
    74
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    75
void LogConfiguration::post_initialize() {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    76
  LogDiagnosticCommand::registerCommand();
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37108
diff changeset
    77
  Log(logging) log;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    78
  log.info("Log configuration fully initialized.");
34252
59d76c40998a 8143229: Replace the develop level with develop macros in Unified Logging
mlarsson
parents: 33105
diff changeset
    79
  log_develop_info(logging)("Develop logging is available.");
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    80
  if (log.is_trace()) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    81
    ResourceMark rm;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    82
    describe(log.trace_stream());
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    83
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    84
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    85
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    86
void LogConfiguration::initialize(jlong vm_start_time) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    87
  LogFileOutput::set_file_name_parameters(vm_start_time);
36174
481391df586b 8148219: Add decorator hostname to UL
mlarsson
parents: 35230
diff changeset
    88
  LogDecorations::initialize(vm_start_time);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    89
  assert(_outputs == NULL, "Should not initialize _outputs before this function, initialize called twice?");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    90
  _outputs = NEW_C_HEAP_ARRAY(LogOutput*, 2, mtLogging);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    91
  _outputs[0] = LogOutput::Stdout;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    92
  _outputs[1] = LogOutput::Stderr;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    93
  _n_outputs = 2;
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
void LogConfiguration::finalize() {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    97
  for (size_t i = 2; i < _n_outputs; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    98
    delete _outputs[i];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    99
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   100
  FREE_C_HEAP_ARRAY(LogOutput*, _outputs);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   101
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   102
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   103
size_t LogConfiguration::find_output(const char* name) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   104
  for (size_t i = 0; i < _n_outputs; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   105
    if (strcmp(_outputs[i]->name(), name) == 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   106
      return i;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   107
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   108
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   109
  return SIZE_MAX;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   110
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   111
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   112
LogOutput* LogConfiguration::new_output(char* name, const char* options, outputStream* errstream) {
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   113
  const char* type;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   114
  char* equals_pos = strchr(name, '=');
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   115
  if (equals_pos == NULL) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   116
    type = "file";
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   117
  } else {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   118
    *equals_pos = '\0';
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   119
    type = name;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   120
    name = equals_pos + 1;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   121
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   122
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   123
  // Check if name is quoted, and if so, strip the quotes
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   124
  char* quote = strchr(name, '"');
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   125
  if (quote != NULL) {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   126
    char* end_quote = strchr(name + 1, '"');
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   127
    if (end_quote == NULL) {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   128
      errstream->print_cr("Output name has opening quote but is missing a terminating quote.");
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   129
      return NULL;
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   130
    } else if (quote != name || end_quote[1] != '\0') {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   131
      errstream->print_cr("Output name can not be partially quoted."
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   132
                          " Either surround the whole name with quotation marks,"
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   133
                          " or do not use quotation marks at all.");
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   134
      return NULL;
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   135
    }
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   136
    name++;
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   137
    *end_quote = '\0';
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   138
  }
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   139
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   140
  LogOutput* output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   141
  if (strcmp(type, "file") == 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   142
    output = new LogFileOutput(name);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   143
  } else {
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   144
    errstream->print_cr("Unsupported log output type.");
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   145
    return NULL;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   146
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   147
37465
1d5551f466ee 8146879: Add option for handling existing log files in UL
mlarsson
parents: 37242
diff changeset
   148
  bool success = output->initialize(options, errstream);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   149
  if (!success) {
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   150
    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
   151
    delete output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   152
    return NULL;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   153
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   154
  return output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   155
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   156
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   157
size_t LogConfiguration::add_output(LogOutput* output) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   158
  size_t idx = _n_outputs++;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   159
  _outputs = REALLOC_C_HEAP_ARRAY(LogOutput*, _outputs, _n_outputs, mtLogging);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   160
  _outputs[idx] = output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   161
  return idx;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   162
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   163
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   164
void LogConfiguration::delete_output(size_t idx) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   165
  assert(idx > 1 && idx < _n_outputs,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 33097
diff changeset
   166
         "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
   167
         " and _n_outputs = " SIZE_FORMAT, idx, _n_outputs);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   168
  LogOutput* output = _outputs[idx];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   169
  // Swap places with the last output and shrink the array
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   170
  _outputs[idx] = _outputs[--_n_outputs];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   171
  _outputs = REALLOC_C_HEAP_ARRAY(LogOutput*, _outputs, _n_outputs, mtLogging);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   172
  delete output;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   173
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   174
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   175
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
   176
  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
   177
  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
   178
  LogOutput* output = _outputs[idx];
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   179
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   180
  // Clear the previous config description
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   181
  output->clear_config_string();
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   182
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   183
  bool enabled = false;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   184
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   185
    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
   186
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   187
    // 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
   188
    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
   189
      continue;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   190
    }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   191
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   192
    // Update decorators before adding/updating output level,
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   193
    // so that the tagset will have the necessary decorators when requiring them.
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   194
    if (level != LogLevel::Off) {
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   195
      ts->update_decorators(decorators);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   196
    }
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   197
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   198
    // Set the new level, if it changed
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   199
    if (level != LogLevel::NotMentioned) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   200
      ts->set_output_level(output, level);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   201
    }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   202
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   203
    if (level != LogLevel::Off) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   204
      // 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
   205
      enabled = true;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   206
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   207
      if (level == LogLevel::NotMentioned) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   208
        // 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
   209
        level = ts->level_for(output);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   210
      }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   211
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   212
      // 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
   213
      output->add_to_config_string(ts, level);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   214
    }
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   215
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   216
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   217
  // 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
   218
  output->set_decorators(decorators);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   219
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   220
  // 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
   221
  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
   222
    ts->update_decorators();
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   223
  }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   224
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   225
  if (enabled) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   226
    assert(strlen(output->config_string()) > 0,
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   227
           "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
   228
  } else if (idx > 1) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   229
    // Output is unused and should be removed.
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   230
    delete_output(idx);
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   231
  } else {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   232
    // 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
   233
    // 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
   234
    output->set_config_string("all=off");
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   235
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   236
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   237
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   238
void LogConfiguration::disable_output(size_t idx) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   239
  LogOutput* out = _outputs[idx];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   240
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   241
  // Remove the output from all tagsets.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   242
  for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   243
    ts->set_output_level(out, LogLevel::Off);
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   244
    ts->update_decorators();
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   245
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   246
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   247
  // Delete the output unless stdout/stderr
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   248
  if (out != LogOutput::Stderr && out != LogOutput::Stdout) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   249
    delete_output(find_output(out->name()));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   250
  } else {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   251
    out->set_config_string("all=off");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   252
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   253
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   254
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   255
void LogConfiguration::disable_logging() {
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   256
  ConfigurationLock cl;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   257
  for (size_t i = 0; i < _n_outputs; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   258
    disable_output(i);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   259
  }
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   260
  notify_update_listeners();
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   261
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   262
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   263
void LogConfiguration::configure_stdout(LogLevelType level, bool exact_match, ...) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   264
  size_t i;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   265
  va_list ap;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   266
  LogTagLevelExpression expr;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   267
  va_start(ap, exact_match);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   268
  for (i = 0; i < LogTag::MaxTags; i++) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   269
    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
   270
    expr.add_tag(tag);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   271
    if (tag == LogTag::__NO_TAG) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   272
      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
   273
      break;
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   274
    }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   275
  }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   276
  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
   277
         "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
   278
  va_end(ap);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   279
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   280
  if (!exact_match) {
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   281
    expr.set_allow_other_tags();
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   282
  }
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   283
  expr.set_level(level);
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   284
  expr.new_combination();
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   285
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   286
  // 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
   287
  ConfigurationLock cl;
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   288
  configure_output(0, expr, LogOutput::Stdout->decorators());
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   289
  notify_update_listeners();
34316
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   290
}
4d876653d940 8142952: Unified Logging framework does not allow multiple -Xlog: arguments.
mlarsson
parents: 34252
diff changeset
   291
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   292
bool LogConfiguration::parse_command_line_arguments(const char* opts) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   293
  char* copy = os::strdup_check_oom(opts, mtLogging);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   294
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   295
  // 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
   296
  char* str = copy;
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   297
  char* substrings[4] = {0};
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   298
  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
   299
    substrings[i] = str;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   300
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   301
    // 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
   302
    char* next = strpbrk(str, ":\"");
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   303
    while (next != NULL && *next == '"') {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   304
      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
   305
      if (end_quote == NULL) {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   306
        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
   307
        os::free(copy);
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   308
        return false;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   309
      }
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   310
      // 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
   311
      next = strpbrk(end_quote + 1, ":\"");
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   312
    }
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   313
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   314
    if (next != NULL) {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   315
      *next = '\0';
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   316
      str = next + 1;
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   317
    } else {
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   318
      break;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   319
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   320
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   321
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   322
  // 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
   323
  char* what = substrings[0];
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   324
  char* output = substrings[1];
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   325
  char* decorators = substrings[2];
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   326
  char* output_options = substrings[3];
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   327
  char errbuf[512];
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   328
  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
   329
  bool success = parse_log_arguments(output, what, decorators, output_options, &ss);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   330
  if (!success) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   331
    errbuf[strlen(errbuf) - 1] = '\0'; // Strip trailing newline.
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   332
    log_error(logging)("%s", errbuf);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   333
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   334
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   335
  os::free(copy);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   336
  return success;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   337
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   338
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   339
bool LogConfiguration::parse_log_arguments(const char* outputstr,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   340
                                           const char* what,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   341
                                           const char* decoratorstr,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   342
                                           const char* output_options,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   343
                                           outputStream* errstream) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   344
  if (outputstr == NULL || strlen(outputstr) == 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   345
    outputstr = "stdout";
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   346
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   347
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   348
  LogTagLevelExpression expr;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   349
  if (!expr.parse(what, errstream)) {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   350
    return false;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   351
  }
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   352
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   353
  LogDecorators decorators;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   354
  if (!decorators.parse(decoratorstr, errstream)) {
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   355
    return false;
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   356
  }
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   357
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   358
  ConfigurationLock cl;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   359
  size_t idx;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   360
  if (outputstr[0] == '#') {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   361
    int ret = sscanf(outputstr+1, SIZE_FORMAT, &idx);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   362
    if (ret != 1 || idx >= _n_outputs) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   363
      errstream->print_cr("Invalid output index '%s'", outputstr);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   364
      return false;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   365
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   366
  } else {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   367
    idx = find_output(outputstr);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   368
    if (idx == SIZE_MAX) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   369
      char* tmp = os::strdup_check_oom(outputstr, mtLogging);
35229
b8d78ee728b2 8144220: UL does not support full path names for log files on windows
mlarsson
parents: 35228
diff changeset
   370
      LogOutput* output = new_output(tmp, output_options, errstream);
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   371
      os::free(tmp);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   372
      if (output == NULL) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   373
        return false;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   374
      }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   375
      idx = add_output(output);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   376
    } else if (output_options != NULL && strlen(output_options) > 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   377
      errstream->print_cr("Output options for existing outputs are ignored.");
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
  configure_output(idx, expr, decorators);
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   381
  notify_update_listeners();
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   382
  return true;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   383
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   384
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   385
void LogConfiguration::describe(outputStream* out) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   386
  out->print("Available log levels:");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   387
  for (size_t i = 0; i < LogLevel::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   388
    out->print("%s %s", (i == 0 ? "" : ","), LogLevel::name(static_cast<LogLevelType>(i)));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   389
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   390
  out->cr();
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   391
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   392
  out->print("Available log decorators:");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   393
  for (size_t i = 0; i < LogDecorators::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   394
    LogDecorators::Decorator d = static_cast<LogDecorators::Decorator>(i);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   395
    out->print("%s %s (%s)", (i == 0 ? "" : ","), LogDecorators::name(d), LogDecorators::abbreviation(d));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   396
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   397
  out->cr();
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   398
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   399
  out->print("Available log tags:");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   400
  for (size_t i = 1; i < LogTag::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   401
    out->print("%s %s", (i == 1 ? "" : ","), LogTag::name(static_cast<LogTagType>(i)));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   402
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   403
  out->cr();
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   404
35228
e7bbfb90fd31 8145083: Use semaphore instead of mutex for synchronization of Unified Logging configuration
mlarsson
parents: 34637
diff changeset
   405
  ConfigurationLock cl;
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   406
  out->print_cr("Log output configuration:");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   407
  for (size_t i = 0; i < _n_outputs; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   408
    out->print("#" SIZE_FORMAT ": %s %s ", i, _outputs[i]->name(), _outputs[i]->config_string());
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   409
    for (size_t d = 0; d < LogDecorators::Count; d++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   410
      LogDecorators::Decorator decorator = static_cast<LogDecorators::Decorator>(d);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   411
      if (_outputs[i]->decorators().is_decorator(decorator)) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   412
        out->print("%s,", LogDecorators::name(decorator));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   413
      }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   414
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   415
    out->cr();
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   416
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   417
}
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   418
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   419
void LogConfiguration::print_command_line_help(FILE* out) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   420
  jio_fprintf(out, "-Xlog Usage: -Xlog[:[what][:[output][:[decorators][:output-options]]]]\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   421
              "\t where 'what' is a combination of tags and levels on the form tag1[+tag2...][*][=level][,...]\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   422
              "\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
   423
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   424
  jio_fprintf(out, "Available log levels:\n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   425
  for (size_t i = 0; i < LogLevel::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   426
    jio_fprintf(out, "%s %s", (i == 0 ? "" : ","), LogLevel::name(static_cast<LogLevelType>(i)));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   427
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   428
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   429
  jio_fprintf(out, "\n\nAvailable log decorators: \n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   430
  for (size_t i = 0; i < LogDecorators::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   431
    LogDecorators::Decorator d = static_cast<LogDecorators::Decorator>(i);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   432
    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
   433
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   434
  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
   435
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   436
  jio_fprintf(out, "Available log tags:\n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   437
  for (size_t i = 1; i < LogTag::Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   438
    jio_fprintf(out, "%s %s", (i == 1 ? "" : ","), LogTag::name(static_cast<LogTagType>(i)));
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   439
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   440
  jio_fprintf(out, "\n Specifying 'all' instead of a tag combination matches all tag combinations.\n\n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   441
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   442
  jio_fprintf(out, "Available log outputs:\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   443
              " stdout, stderr, file=<filename>\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   444
              " 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
   445
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   446
              "Some examples:\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   447
              " -Xlog\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   448
              "\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
   449
              "\t (Equivalent to -Xlog:all=info:stdout:uptime,levels,tags).\n\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   450
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   451
              " -Xlog:gc\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   452
              "\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
   453
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   454
              " -Xlog:gc=debug:file=gc.txt:none\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   455
              "\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
   456
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   457
              " -Xlog:gc=trace:file=gctrace.txt:uptimemillis,pids:filecount=5,filesize=1024\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   458
              "\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
   459
              "\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
   460
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   461
              " -Xlog:gc::uptime,tid\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   462
              "\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
   463
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   464
              " -Xlog:gc*=info,rt*=off\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   465
              "\t Log messages tagged with at least 'gc' using 'info' level, but turn off logging of messages tagged with 'rt'.\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   466
              "\t (Messages tagged with both 'gc' and 'rt' will not be logged.)\n\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   467
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   468
              " -Xlog:disable -Xlog:rt=trace:rttrace.txt\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   469
              "\t Turn off all logging, including warnings and errors,\n"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   470
              "\t and then enable messages tagged with 'rt' using 'trace' level to file 'rttrace.txt'.\n");
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
   471
}
34637
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   472
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   473
void LogConfiguration::rotate_all_outputs() {
35230
a528ea8203ec 8145294: TestLogRotation.java triggers a race in the UL framework
mlarsson
parents: 35229
diff changeset
   474
  // 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
   475
  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
   476
    _outputs[idx]->force_rotate();
34637
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   477
  }
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   478
}
9b9298044d23 8140556: Add force rotation option to VM.log jcmd
ysuenaga
parents: 34316
diff changeset
   479
37108
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   480
void LogConfiguration::register_update_listener(UpdateListenerFunction cb) {
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   481
  assert(cb != NULL, "Should not register NULL as listener");
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   482
  ConfigurationLock cl;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   483
  size_t idx = _n_listener_callbacks++;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   484
  _listener_callbacks = REALLOC_C_HEAP_ARRAY(UpdateListenerFunction,
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   485
                                             _listener_callbacks,
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   486
                                             _n_listener_callbacks,
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   487
                                             mtLogging);
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   488
  _listener_callbacks[idx] = cb;
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   489
}
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   490
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   491
void LogConfiguration::notify_update_listeners() {
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   492
  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
   493
  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
   494
    _listener_callbacks[i]();
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   495
  }
fe800ec86077 8151264: Add a notification mechanism for UL configuration changes.
rehn
parents: 36174
diff changeset
   496
}