src/hotspot/share/logging/logLevel.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 49163 580bb0b85f63
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
     1
/*
49163
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
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"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    25
#include "logging/logLevel.hpp"
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    26
#include "utilities/globalDefinitions.hpp"
49163
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    27
#include "utilities/stringUtils.hpp"
33097
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    28
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    29
const char* LogLevel::_name[] = {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    30
  "off",
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    31
#define LOG_LEVEL(name, printname) #printname,
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    32
  LOG_LEVEL_LIST
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    33
#undef LOG_LEVEL
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    34
};
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    35
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    36
LogLevelType LogLevel::from_string(const char* str) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    37
  for (uint i = 0; i < Count; i++) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    38
    if (strcasecmp(str, _name[i]) == 0) {
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    39
      return static_cast<LogLevelType>(i);
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    40
    }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    41
  }
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    42
  return Invalid;
96e348cb0442 8046148: JEP 158: Unified JVM Logging
mlarsson
parents:
diff changeset
    43
}
49163
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    44
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    45
LogLevelType LogLevel::fuzzy_match(const char *level) {
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    46
  size_t len = strlen(level);
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    47
  LogLevelType match = LogLevel::Invalid;
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    48
  double best = 0.4; // required similarity to be considered a match
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    49
  for (uint i = 1; i < Count; i++) {
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    50
    LogLevelType cur = static_cast<LogLevelType>(i);
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    51
    const char* levelname = LogLevel::name(cur);
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    52
    double score = StringUtils::similarity(level, len, levelname, strlen(levelname));
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    53
    if (score >= best) {
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    54
      match = cur;
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    55
      best= score;
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    56
    }
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    57
  }
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    58
  return match;
580bb0b85f63 8198554: Add fuzzy matching for log levels and tags when parsing -Xlog
mlarsson
parents: 47216
diff changeset
    59
}