Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Fix log4j error messages when app is run
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Oct 17, 2019
1 parent e310005 commit 57f7f25
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion runSystemCommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
################################################

FRAMEWORK_JMX_COMMAND_CLIENT_VERSION=2.2.1-SNAPSHOT
FRAMEWORK_JMX_COMMAND_CLIENT_VERSION=2.2.2-SNAPSHOT
CONTEXT_NAME="people"
USER_NAME="admin"
PASSWORD="admin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static java.lang.String.format;
import static java.time.Duration.between;
import static org.apache.commons.lang3.time.DurationFormatUtils.formatDurationHMS;
import static org.apache.commons.lang3.time.DurationFormatUtils.formatDuration;
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_COMPLETE;
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_FAILED;

Expand Down Expand Up @@ -37,22 +37,22 @@ public boolean commandComplete(final SystemCommanderMBean systemCommanderMBean,
final ZonedDateTime endTime = clock.now();
final long durationMillis = between(startTime, endTime).toMillis();

final String duration = formatDurationHMS(durationMillis);
final String duration = formatDuration(durationMillis, "HH:mm:ss");
toConsolePrinter.println(format("Command %s complete", commandStatus.getSystemCommandName()));
toConsolePrinter.println(format("%s duration %s (hours:minutes:seconds:milliseconds)", commandStatus.getSystemCommandName(), duration));
toConsolePrinter.println(format("%s duration %s (hours:minutes:seconds)", commandStatus.getSystemCommandName(), duration));
return true;
}

if(commandState == COMMAND_FAILED) {
final long durationMillis = between(startTime, clock.now()).toMillis();

final String duration = formatDurationHMS(durationMillis);
final String duration = formatDuration(durationMillis, "HH:mm:ss");
final String errorMessage = commandStatus.getMessage();
final String systemCommandName = commandStatus.getSystemCommandName();

toConsolePrinter.println(format("ERROR: Command %s failed", systemCommandName));
toConsolePrinter.println(format("ERROR: %s", errorMessage));
toConsolePrinter.println(format("%s duration %s (hours:minutes:seconds:milliseconds)", commandStatus.getSystemCommandName(), duration));
toConsolePrinter.println(format("%s duration %s (hours:minutes:seconds)", commandStatus.getSystemCommandName(), duration));

throw new SystemCommandFailedException(format("Comand %s failed. %s", systemCommandName, errorMessage));
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/>
</layout>
</appender>

<root>
<level value="ERROR"/>
<appender-ref ref="console"/>
</root>

</log4j:configuration>


15 changes: 0 additions & 15 deletions src/main/resources/log4j2.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void shouldLogAndReturnTrueIfTheCommandIsComplete() throws Exception {
assertThat(commandChecker.commandComplete(systemCommanderMBean, commandId, startTime), is(true));

verify(toConsolePrinter).println("Command CATCHUP complete");
verify(toConsolePrinter).println("CATCHUP duration 01:23:00.000 (hours:minutes:seconds:milliseconds)");
verify(toConsolePrinter).println("CATCHUP duration 01:23:00 (hours:minutes:seconds)");
}

@Test
Expand Down Expand Up @@ -88,7 +88,7 @@ public void shouldLogAndThrowExceptionfTheCommandFails() throws Exception {

verify(toConsolePrinter).println("ERROR: Command CATCHUP failed");
verify(toConsolePrinter).println("ERROR: CATCHUP failed with 23 errors");
verify(toConsolePrinter).println("CATCHUP duration 01:23:00.000 (hours:minutes:seconds:milliseconds)");
verify(toConsolePrinter).println("CATCHUP duration 01:23:00 (hours:minutes:seconds)");
}

@Test
Expand Down

0 comments on commit 57f7f25

Please sign in to comment.