Skip to content

Commit

Permalink
MID-8842 ninja - logging improvements
Browse files Browse the repository at this point in the history
(cherry picked from commit 3cb4ed7)
  • Loading branch information
1azyman committed Aug 4, 2023
1 parent bd38964 commit 9f67838
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void setErr(@NotNull PrintStream err) {
this.err = err;
}

// todo main doesn't return error code non zero if error occurs, fix this
protected <T> @NotNull MainResult<?> run(String[] args) {
AnsiConsole.systemInstall();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ public Void execute() throws Exception {
log.info("Running scripts in raw mode using custom JDBC url/username/password options.");

if (options.getScripts().isEmpty()) {
log.warn("No scripts to run.");
return null;
}

// setup custom datasource
try (HikariDataSource dataSource = setupCustomDataSource()) {
executeScripts(dataSource, options.getScripts());
}

return null;
}

log.info("Running scripts against midpoint {}.", mode.name().toLowerCase());
log.info(ConsoleFormat.formatMessageWithInfoParameters("Running scripts against midpoint {}.", mode.name().toLowerCase()));

final ApplicationContext applicationContext = context.getApplicationContext();
final MidpointConfiguration midpointConfiguration = applicationContext.getBean(MidpointConfiguration.class);
Expand All @@ -97,7 +97,6 @@ public Void execute() throws Exception {
repositoryDataSource = createDataSource(configuration, "ninja-repository");
if (mode == RunSqlOptions.Mode.REPOSITORY) {
executeScripts(repositoryDataSource, options.getScripts());

return null;
}

Expand Down Expand Up @@ -225,8 +224,10 @@ private void executeScripts(@NotNull DataSource dataSource, @NotNull List<File>

stmt.close();

log.info(ConsoleFormat.formatSuccessMessage("Script executed successfully."));
log.info("Script executed successfully");
}

log.info(ConsoleFormat.formatSuccessMessage("Scripts executed successfully."));
} finally {
connection.setAutoCommit(autocommit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@

package com.evolveum.midpoint.ninja.impl;

import com.evolveum.midpoint.ninja.util.ConsoleFormat;

import org.fusesource.jansi.Ansi;

public enum LogLevel {

ERROR("ERROR", Ansi.Color.RED),
ERROR("ERROR", ConsoleFormat.Color.ERROR.color),

WARNING("WARNING", Ansi.Color.YELLOW),
WARNING("WARNING", ConsoleFormat.Color.WARN.color),

INFO("INFO", Ansi.Color.BLUE),
INFO("INFO", ConsoleFormat.Color.INFO.color),

DEBUG("DEBUG", Ansi.Color.DEFAULT);
DEBUG("DEBUG", ConsoleFormat.Color.DEFAULT.color);

private final String label;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import com.evolveum.midpoint.ninja.action.Action;
import com.evolveum.midpoint.ninja.impl.LogLevel;

/**
* TODO think this through - how to format different messages
*/
public final class ConsoleFormat {

public enum Color {
Expand Down

0 comments on commit 9f67838

Please sign in to comment.