Skip to content

Commit

Permalink
WIP of messing around with structured logging
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenMassaro committed Dec 1, 2022
1 parent e91c17f commit d2794ec
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
Expand Up @@ -632,9 +632,11 @@ protected Map<String, Object> configureLogging() throws IOException {
private void configureLogging(Level logLevel, String logFile) throws IOException {
configuredLogLevel = logLevel;

final JavaLogService logService = (JavaLogService) Scope.getCurrentScope().get(Scope.Attr.logService, LogService.class);
final LogService logService = Scope.getCurrentScope().get(Scope.Attr.logService, LogService.class);
java.util.logging.Logger liquibaseLogger = java.util.logging.Logger.getLogger("liquibase");
logService.setParent(liquibaseLogger);
if (logService instanceof JavaLogService) {
((JavaLogService) logService).setParent(liquibaseLogger);
}

System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] %4$s [%2$s] %5$s%6$s%n");

Expand Down
Expand Up @@ -54,6 +54,7 @@ public void run(CommandResultsBuilder resultsBuilder) throws Exception {
outputBestPracticeMessage();

String changeLogFile = StringUtil.trimToNull(commandScope.getArgumentValue(CHANGELOG_FILE_ARG));
Scope.getCurrentScope().getLog(getClass()).mdc(CHANGELOG_FILE_ARG.getName(), changeLogFile);
if (changeLogFile != null && changeLogFile.toLowerCase().endsWith(".sql")) {
Scope.getCurrentScope().getUI().sendMessage("\n" + INFO_MESSAGE + "\n");
Scope.getCurrentScope().getLog(getClass()).info("\n" + INFO_MESSAGE + "\n");
Expand Down
Expand Up @@ -1793,6 +1793,9 @@ protected void doMigration() throws Exception {
if (commandParams.contains("--" + OPTIONS.VERBOSE)) {
runVerbose = true;
}
Scope.getCurrentScope().getLog(getClass()).severe("qqqq - no mdc");
Scope.getCurrentScope().getLog(getClass()).mdc("qqqq", "added mdc");
Scope.getCurrentScope().getLog(getClass()).severe("qqqq - after mdc");
liquibase.reportStatus(runVerbose, new Contexts(contexts), new LabelExpression(getLabelFilter()),
getOutputWriter());
return;
Expand Down
2 changes: 2 additions & 0 deletions liquibase-core/src/main/java/liquibase/logging/Logger.java
Expand Up @@ -20,6 +20,8 @@ default void close() throws Exception {
*/
void log(Level level, String message, Throwable e);

void mdc(String key, String value);


/**
* Log that a severe error that occurred.
Expand Down
Expand Up @@ -93,4 +93,9 @@ public void debug(String message, Throwable e) {
protected String filterMessage(String message) {
return message;
}

@Override
public void mdc(String key, String value) {
// Do nothing by default
}
}

0 comments on commit d2794ec

Please sign in to comment.