mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
add log4j2 programmatic configuration
This commit is contained in:
@@ -40,8 +40,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class NBCLI {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger("NBCLI");
|
||||
private static final Logger EVENTS = LoggerFactory.getLogger("EVENTS");
|
||||
private static Logger logger;
|
||||
|
||||
private static final String CHART_HDR_LOG_NAME = "hdrdata-for-chart.log";
|
||||
|
||||
@@ -68,6 +67,14 @@ public class NBCLI {
|
||||
|
||||
public void run(String[] args) {
|
||||
|
||||
// Initial logging config covers only command line parsing
|
||||
// We don't want anything to go to console here unless it is a real problem
|
||||
// as some integrations will depend on a stable and parsable program output
|
||||
LoggerConfig loggerConfig = new LoggerConfig(NBLogLevel.ERROR, NBLogLevel.ERROR);
|
||||
|
||||
ConfigurationFactory.setConfigurationFactory(loggerConfig);
|
||||
logger = LogManager.getLogger("NBCLI");
|
||||
|
||||
NBCLIOptions globalOptions = new NBCLIOptions(args, NBCLIOptions.Mode.ParseGlobalsOnly);
|
||||
|
||||
// Global only processing
|
||||
@@ -128,11 +135,10 @@ public class NBCLI {
|
||||
|
||||
String sessionName = new SessionNamer().format(options.getSessionName());
|
||||
|
||||
ConsoleLogging.enableConsoleLogging(options.wantsConsoleLogLevel(), options.getConsoleLoggingPattern());
|
||||
|
||||
Annotators.init(options.getAnnotatorsConfig());
|
||||
Annotators.recordAnnotation(sessionName, 0L, 0L,
|
||||
Map.of(), Map.of());
|
||||
SessionLogConfig sessionLogConfig = new SessionLogConfig(sessionName);
|
||||
sessionLogConfig.setConsolePattern(options.getConsoleLoggingPattern());
|
||||
sessionLogConfig.setLevel(options.wantsConsoleLogLevel());
|
||||
sessionLogConfig.start();
|
||||
|
||||
ActivityMetrics.setHdrDigits(options.getHdrDigits());
|
||||
|
||||
@@ -312,13 +318,12 @@ public class NBCLI {
|
||||
}
|
||||
|
||||
|
||||
Level consoleLogLevel = options.wantsConsoleLogLevel();
|
||||
Level scenarioLogLevel = Level.toLevel(options.getLogsLevel());
|
||||
if (scenarioLogLevel.toInt() > consoleLogLevel.toInt()) {
|
||||
NBLogLevel consoleLogLevel = options.wantsConsoleLogLevel();
|
||||
NBLogLevel scenarioLogLevel = options.getScenarioLogLevel();
|
||||
if (scenarioLogLevel.isGreaterOrEqualTo(consoleLogLevel)) {
|
||||
logger.info("raising scenario logging level to accommodate console logging level");
|
||||
}
|
||||
|
||||
Level maxLevel = Level.toLevel(Math.min(consoleLogLevel.toInt(), scenarioLogLevel.toInt()));
|
||||
NBLogLevel maxLevel = NBLogLevel.max(consoleLogLevel, scenarioLogLevel);
|
||||
|
||||
// Execute Scenario!
|
||||
if (options.getCommands().size() == 0) {
|
||||
@@ -330,7 +335,10 @@ public class NBCLI {
|
||||
ScriptParams scriptParams = new ScriptParams();
|
||||
scriptParams.putAll(buffer.getCombinedParams());
|
||||
scenario.addScenarioScriptParams(scriptParams);
|
||||
ScenarioLogger sl = new ScenarioLogger(scenario)
|
||||
|
||||
Path scenarioLogPath = SessionLogConfig.composeSessionLogName(options.getLogsDirectory(), scenario.getScenarioName());
|
||||
logger.info("Configuring scenario log at " + scenarioLogPath.toString());
|
||||
ScenarioLogger sl = new SessionLogConfig(scenario.getScenarioName())
|
||||
.setLogDir(options.getLogsDirectory())
|
||||
.setMaxLogs(options.getLogsMax())
|
||||
.setLevel(maxLevel)
|
||||
|
||||
@@ -90,7 +90,9 @@ public class NBCLIOptions {
|
||||
private static final String GRAALJS_COMPAT = "--graaljs-compat";
|
||||
private static final String DOCKER_GRAFANA_TAG = "--docker-grafana-tag";
|
||||
|
||||
private static final String DEFAULT_CONSOLE_LOGGING_PATTERN = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n";
|
||||
private static final String DEFAULT_CONSOLE_LOGGING_PATTERN = "%7r %-5level [%t] %-12logger{0} %msg%n%throwable";
|
||||
|
||||
// private static final String DEFAULT_CONSOLE_LOGGING_PATTERN = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n";
|
||||
public static final String NBSTATEDIR = "NBSTATEDIR";
|
||||
|
||||
private final LinkedList<Cmd> cmdList = new LinkedList<>();
|
||||
@@ -670,8 +672,8 @@ public class NBCLIOptions {
|
||||
return reportCsvTo;
|
||||
}
|
||||
|
||||
public String getLogsDirectory() {
|
||||
return logsDirectory;
|
||||
public Path getLogsDirectory() {
|
||||
return Path.of(logsDirectory);
|
||||
}
|
||||
|
||||
public int getLogsMax() {
|
||||
|
||||
Reference in New Issue
Block a user