Skip to content

Commit

Permalink
structured logging MdcKey renaming (#3875)
Browse files Browse the repository at this point in the history
Rename some MdcKey properties to correct them.
  • Loading branch information
StevenMassaro committed Mar 2, 2023
1 parent c2d4da1 commit fd07dbf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion liquibase-core/src/main/java/liquibase/Liquibase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ private void logDeploymentOutcomeMdc(boolean success) throws IOException {
String successLog = "Update command completed successfully.";
String failureLog = "Update command encountered an exception.";
try (MdcObject deploymentOutcomeMdc = Scope.getCurrentScope().addMdcValue(MdcKey.DEPLOYMENT_OUTCOME, success ? MdcValue.COMMAND_SUCCESSFUL : MdcValue.COMMAND_FAILED);
MdcObject deploymentOutcomeCountMdc = Scope.getCurrentScope().addMdcValue(MdcKey.DEPLOYMENT_CHANGESET_COUNT, String.valueOf(deployedChangeSetCount))) {
MdcObject deploymentOutcomeCountMdc = Scope.getCurrentScope().addMdcValue(MdcKey.DEPLOYMENT_OUTCOME_COUNT, String.valueOf(deployedChangeSetCount))) {
Scope.getCurrentScope().getLog(getClass()).info(success ? successLog : failureLog);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public CommandResults execute() throws CommandExecutionException {
CommandResultsBuilder resultsBuilder = new CommandResultsBuilder(this, outputStream);
final List<CommandStep> pipeline = commandDefinition.getPipeline();
validate();
Scope.getCurrentScope().addMdcValue(MdcKey.OPERATION_TYPE, StringUtil.join(commandDefinition.getName(), "-"));
Scope.getCurrentScope().addMdcValue(MdcKey.LIQUIBASE_OPERATION, StringUtil.join(commandDefinition.getName(), "-"));
try {
for (CommandStep command : pipeline) {
command.run(resultsBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void execute(SqlStatement statement, Database database, ExecuteJdb
jdbcQuery.execute(Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database));
logSuccess();
} catch (DatabaseException e) {
Scope.getCurrentScope().addMdcValue(MdcKey.DATABASE_CHANGELOG_OUTCOME, MdcValue.DATABASE_CHANGELOG_OUTCOME_FAILED);
Scope.getCurrentScope().addMdcValue(MdcKey.DATABASE_CHANGELOG_TABLE_OUTCOME, MdcValue.DATABASE_CHANGELOG_OUTCOME_FAILED);
throw new DatabaseException(e);
}
}
Expand All @@ -54,7 +54,7 @@ public static <T> T query(SqlStatement statement, Database database, QueryJdbc<T
logSuccess();
return value;
} catch (DatabaseException e) {
Scope.getCurrentScope().addMdcValue(MdcKey.DATABASE_CHANGELOG_OUTCOME, MdcValue.DATABASE_CHANGELOG_OUTCOME_FAILED);
Scope.getCurrentScope().addMdcValue(MdcKey.DATABASE_CHANGELOG_TABLE_OUTCOME, MdcValue.DATABASE_CHANGELOG_OUTCOME_FAILED);
throw new DatabaseException(e);
}
}
Expand All @@ -64,9 +64,9 @@ private static void addSqlMdc(SqlStatement statement, Database database) {
}

private static void logSuccess() {
Scope.getCurrentScope().addMdcValue(MdcKey.DATABASE_CHANGELOG_OUTCOME, MdcValue.DATABASE_CHANGELOG_OUTCOME_SUCCESS);
Scope.getCurrentScope().addMdcValue(MdcKey.DATABASE_CHANGELOG_TABLE_OUTCOME, MdcValue.DATABASE_CHANGELOG_OUTCOME_SUCCESS);
Scope.getCurrentScope().getLog(ChangelogJdbcMdcListener.class).info("Changelog query completed.");
Scope.getCurrentScope().getMdcManager().remove(MdcKey.DATABASE_CHANGELOG_OUTCOME);
Scope.getCurrentScope().getMdcManager().remove(MdcKey.DATABASE_CHANGELOG_TABLE_OUTCOME);
Scope.getCurrentScope().getMdcManager().remove(MdcKey.DATABASE_CHANGELOG_SQL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ protected void doMigration() throws Exception {

try {
if (COMMANDS.UPDATE.equalsIgnoreCase(command)) {
Scope.getCurrentScope().addMdcValue(MdcKey.OPERATION_TYPE, COMMANDS.UPDATE);
Scope.getCurrentScope().addMdcValue(MdcKey.LIQUIBASE_OPERATION, COMMANDS.UPDATE);
try {
Map<String, Object> updateScopedObjects = new HashMap<>();
updateScopedObjects.put("showSummary", showSummary);
Expand Down Expand Up @@ -1826,7 +1826,7 @@ protected void doMigration() throws Exception {
} else if (COMMANDS.UPDATE_SQL.equalsIgnoreCase(command)) {
liquibase.update(new Contexts(contexts), new LabelExpression(getLabelFilter()), getOutputWriter());
} else if (COMMANDS.ROLLBACK.equalsIgnoreCase(command)) {
Scope.getCurrentScope().addMdcValue(MdcKey.OPERATION_TYPE, COMMANDS.ROLLBACK);
Scope.getCurrentScope().addMdcValue(MdcKey.LIQUIBASE_OPERATION, COMMANDS.ROLLBACK);
if (getCommandArgument() == null) {
throw new CommandLineParsingException(
String.format(coreBundle.getString("command.requires.tag"), COMMANDS.ROLLBACK));
Expand All @@ -1842,7 +1842,7 @@ protected void doMigration() throws Exception {
liquibase.rollback(new ISODateFormat().parse(getCommandArgument()), getCommandParam
(COMMANDS.ROLLBACK_SCRIPT, null), new Contexts(contexts), new LabelExpression(getLabelFilter()));
} else if (COMMANDS.ROLLBACK_COUNT.equalsIgnoreCase(command)) {
Scope.getCurrentScope().addMdcValue(MdcKey.OPERATION_TYPE, COMMANDS.ROLLBACK_COUNT);
Scope.getCurrentScope().addMdcValue(MdcKey.LIQUIBASE_OPERATION, COMMANDS.ROLLBACK_COUNT);
liquibase.rollback(Integer.parseInt(getCommandArgument()), getCommandParam
(COMMANDS.ROLLBACK_SCRIPT, null), new Contexts(contexts), new LabelExpression(getLabelFilter()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class MdcKey {
public static final String CHANGESET_AUTHOR = "changesetAuthor";
public static final String CHANGESET_FILEPATH = "changesetFilepath";
public static final String CHANGESET_OUTCOME = "changesetOutcome";
public static final String OPERATION_TYPE = "liquibaseOperation";
public static final String LIQUIBASE_OPERATION = "liquibaseOperation";
public static final String LIQUIBASE_TARGET_URL = "liquibaseTargetUrl";
public static final String LIQUIBASE_REF_URL = "liquibaseRefUrl";
public static final String CHANGESET_OPERATION_START_TIME = "changesetOperationStart";
Expand All @@ -25,14 +25,14 @@ public class MdcKey {
public static final String COMMAND_LABEL_FILTER = "commandLabelFilter";
public static final String CHANGESET_CONTEXT = "changesetContext";
public static final String COMMAND_CONTEXT_FILTER = "commandContextFilter";
public static final String DEPLOYMENT_CHANGESET_COUNT = "deploymentOutcomeCount";
public static final String DEPLOYMENT_OUTCOME_COUNT = "deploymentOutcomeCount";
public static final String CHANGELOG_PROPERTIES = "changelogProperties";
public static final String ROLLBACK_COUNT = "rollbackCount";
public static final String CHANGESETS_ROLLED_BACK = "changesetsRolledback";
public static final String ROLLBACK_ONE_CHANGESET_FORCE = "rollbackOneChangesetForce";
public static final String ROLLBACK_ONE_UPDATE_FORCE = "rollbackOneUpdateForce";
public static final String ROLLBACK_TO_DATE = "rollbackToDate";
public static final String DATABASE_CHANGELOG_SQL = "databaseChangelogSQL";
public static final String DATABASE_CHANGELOG_OUTCOME = "databaseChangelogTableOutcome";
public static final String DATABASE_CHANGELOG_TABLE_OUTCOME = "databaseChangelogTableOutcome";
public static final String ROLLBACK_SQL_FILE = "rollbackSqlFile";
}

0 comments on commit fd07dbf

Please sign in to comment.