Skip to content

Commit

Permalink
Issue checkstyle#3110: Modified DefaultLogger to remove hardcoded mes…
Browse files Browse the repository at this point in the history
…sages and to support i18n for the messages
  • Loading branch information
Subbu Dantu authored and Subbu Dantu committed Jun 26, 2017
1 parent 61f2ef2 commit ef48dd5
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/main/java/com/puppycrawl/tools/checkstyle/DefaultLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
import com.puppycrawl.tools.checkstyle.api.SeverityLevel;

/**
Expand All @@ -42,6 +43,22 @@
*/
public class DefaultLogger extends AutomaticBean implements AuditListener {

/**
* A key pointing to the add exception
* message in the "messages.properties" file.
*/
public static final String ADD_EXCEPTION_MESSAGE = "DefaultLogger.addException";
/**
* A key pointing to the started audit
* message in the "messages.properties" file.
*/
public static final String AUDIT_STARTED_MESSAGE = "DefaultLogger.auditStarted";
/**
* A key pointing to the finished audit
* message in the "messages.properties" file.
*/
public static final String AUDIT_FINISHED_MESSAGE = "DefaultLogger.auditFinished";

/** Where to write info messages. **/
private final PrintWriter infoWriter;
/** Close info stream after use. */
Expand Down Expand Up @@ -127,20 +144,30 @@ public void addError(AuditEvent event) {
@Override
public void addException(AuditEvent event, Throwable throwable) {
synchronized (errorWriter) {
errorWriter.println("Error auditing " + event.getFileName());
final LocalizedMessage addExceptionMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, ADD_EXCEPTION_MESSAGE,
new String[] {event.getFileName()}, null,
LocalizedMessage.class, null);
errorWriter.println(addExceptionMessage.getMessage());
throwable.printStackTrace(errorWriter);
}
}

@Override
public void auditStarted(AuditEvent event) {
infoWriter.println("Starting audit...");
final LocalizedMessage auditStartMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, AUDIT_STARTED_MESSAGE, null, null,
LocalizedMessage.class, null);
infoWriter.println(auditStartMessage.getMessage());
infoWriter.flush();
}

@Override
public void auditFinished(AuditEvent event) {
infoWriter.println("Audit done.");
final LocalizedMessage auditFinishMessage = new LocalizedMessage(0,
Definitions.CHECKSTYLE_BUNDLE, AUDIT_FINISHED_MESSAGE, null, null,
LocalizedMessage.class, null);
infoWriter.println(auditFinishMessage.getMessage());
closeStreams();
}

Expand Down

0 comments on commit ef48dd5

Please sign in to comment.