mirror of
https://github.com/fabioformosa/quartz-manager.git
synced 2025-12-29 13:43:15 +09:00
Added type to log
This commit is contained in:
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.simp.SimpMessageSendingOperations;
|
||||
|
||||
import it.fabioformosa.quartzmanager.aspects.ProgressUpdater;
|
||||
import it.fabioformosa.quartzmanager.jobs.entities.LogRecord;
|
||||
|
||||
public abstract class AbstractLoggingJob implements Job {
|
||||
|
||||
@@ -28,12 +29,12 @@ public abstract class AbstractLoggingJob implements Job {
|
||||
* @param jobExecutionContext
|
||||
* @return final log
|
||||
*/
|
||||
public abstract String doIt(JobExecutionContext jobExecutionContext);
|
||||
public abstract LogRecord doIt(JobExecutionContext jobExecutionContext);
|
||||
|
||||
@Override
|
||||
public final void execute(JobExecutionContext jobExecutionContext) {
|
||||
try {
|
||||
String logMsg = doIt(jobExecutionContext);
|
||||
LogRecord logMsg = doIt(jobExecutionContext);
|
||||
logAndSend(logMsg);
|
||||
progressUpdater.update();
|
||||
} catch (SchedulerException e) {
|
||||
@@ -41,9 +42,9 @@ public abstract class AbstractLoggingJob implements Job {
|
||||
}
|
||||
}
|
||||
|
||||
public void logAndSend(String logMsg) {
|
||||
log.info(logMsg);
|
||||
messagingTemplate.convertAndSend("/topic/logs", logMsg);
|
||||
public void logAndSend(LogRecord logRecord) {
|
||||
log.info(logRecord.getMessage());
|
||||
messagingTemplate.convertAndSend("/topic/logs", logRecord);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,11 +2,14 @@ package it.fabioformosa.quartzmanager.jobs;
|
||||
|
||||
import org.quartz.JobExecutionContext;
|
||||
|
||||
import it.fabioformosa.quartzmanager.jobs.entities.LogRecord;
|
||||
import it.fabioformosa.quartzmanager.jobs.entities.LogRecord.LogType;
|
||||
|
||||
public class SampleJob extends AbstractLoggingJob {
|
||||
|
||||
@Override
|
||||
public String doIt(JobExecutionContext jobExecutionContext) {
|
||||
return "Hello!";
|
||||
public LogRecord doIt(JobExecutionContext jobExecutionContext) {
|
||||
return new LogRecord(LogType.INFO, "Hello!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package it.fabioformosa.quartzmanager.jobs.entities;
|
||||
|
||||
public class LogRecord {
|
||||
|
||||
public enum LogType {
|
||||
INFO, ERROR;
|
||||
}
|
||||
|
||||
private LogType type;
|
||||
private String message;
|
||||
|
||||
public LogRecord(LogType type, String msg) {
|
||||
super();
|
||||
this.type = type;
|
||||
message = msg;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public LogType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setMessage(String msg) {
|
||||
message = msg;
|
||||
}
|
||||
|
||||
public void setType(LogType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LogRecord [type=" + type + ", message=" + message + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,13 +17,14 @@ angular.module('progress')
|
||||
|
||||
$scope.logs = new Array();
|
||||
|
||||
LogService.receive().then(null, null, function(logMsg){
|
||||
LogService.receive().then(null, null, function(logRecord){
|
||||
if($scope.logs.length > MAX_LOGS)
|
||||
$scope.logs.pop();
|
||||
|
||||
var logItem = {};
|
||||
logItem.time = new Date();
|
||||
logItem.msg = logMsg;
|
||||
logItem.type = logRecord.type;
|
||||
logItem.msg = logRecord.message;
|
||||
|
||||
$scope.logs.unshift(logItem);
|
||||
})
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<div id="logs">
|
||||
|
||||
<table id="logTable">
|
||||
<tr data-ng-repeat="log in logs">
|
||||
<td data-ng-class="{'animated zoomIn firstLog': $first}">[{{log.time|date:'medium'}}]</td>
|
||||
<td> </td>
|
||||
<td data-ng-class="{'animated zoomIn firstLog' : $first}">{{log.msg}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="row" data-ng-repeat="log in logs">
|
||||
<div class="col-xs-3">
|
||||
<span data-ng-class="{'animated zoomIn firstLog': $first}"> [{{log.time|date:'medium'}}]</span>
|
||||
</div>
|
||||
<div class="col-xs-2">
|
||||
<span data-ng-class="{'animated zoomIn firstLog': $first}">
|
||||
<i data-ng-class="{'fa fa-check-circle green': log.type == 'INFO', 'fa fa-times-circle red': log.type == 'ERROR'}"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-xs-7">
|
||||
<span data-ng-class="{'animated zoomIn firstLog': $first}"> {{log.msg}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user