Skip to content

Commit

Permalink
SAK-41197 Allow log job to include a stacktrace. (sakaiproject#6468)
Browse files Browse the repository at this point in the history
The test logging job doesn't include a stacktrace, this adds the ability
to include a stacktrace in the test logging event.
  • Loading branch information
buckett authored and bjones86 committed Apr 4, 2019
1 parent 7b29482 commit 87d69fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,27 @@ public class LogMessageJob extends AbstractConfigurableJob {

@Override
public void runJob() throws JobExecutionException {
boolean includeException = getJobExecutionContext().getMergedJobDataMap().getBooleanFromString("stacktrace");
String level = getConfiguredProperty("level");
String message = getConfiguredProperty("message");
String logger = getConfiguredProperty("logger");
Throwable throwable = null;
if (includeException) {
throwable = new Exception("Test Exception").fillInStackTrace();
}
Logger log = LoggerFactory.getLogger(logger);
if ("trace".equalsIgnoreCase(level)) {
log.trace(message);
log.trace(message, throwable);
} else if ("debug".equalsIgnoreCase(level)) {
log.debug(message);
log.debug(message, throwable);
} else if ("info".equalsIgnoreCase(level)) {
log.info(message);
log.info(message, throwable);
} else if ("warn".equalsIgnoreCase(level)) {
log.warn(message);
log.warn(message, throwable);
} else if ("error".equalsIgnoreCase(level)) {
log.error(message);
log.error(message, throwable);
} else if ("fatal".equalsIgnoreCase(level)) {
log.error(fatal, message);
log.error(fatal, message, throwable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ message=Message
message.description=The message to be logged.
logger=Logger
logger.description=The logger to use.
stacktrace=Stacktrace
stacktrace.description=Include stacktrace in log message (boolean: true/false).
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@
<property name="descriptionResourceKey" value="logger.description"/>
<property name="defaultValue" value="org.sakaiproject.component.app.scheduler.jobs.logmessage.LogMessageJob"/>
</bean>
<bean class="org.sakaiproject.component.app.scheduler.jobs.SpringConfigurableJobProperty">
<property name="required" value="false"/>
<property name="labelResourceKey" value="stacktrace"/>
<property name="descriptionResourceKey" value="stacktrace.description"/>
<property name="defaultValue" value="false"/>
</bean>
</set>
</property>
<property name="schedulerManager">
Expand Down

0 comments on commit 87d69fb

Please sign in to comment.