mirror of https://github.com/halo-dev/halo
Change log package to logger
parent
e92328911c
commit
d0576bf653
|
@ -0,0 +1,38 @@
|
||||||
|
package run.halo.app.event.logger;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
import run.halo.app.model.enums.LogType;
|
||||||
|
import run.halo.app.model.params.LogParam;
|
||||||
|
import run.halo.app.utils.ValidationUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author johnniang
|
||||||
|
* @date 19-4-20
|
||||||
|
*/
|
||||||
|
public class LogEvent extends ApplicationEvent {
|
||||||
|
|
||||||
|
private final LogParam logParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new ApplicationEvent.
|
||||||
|
*
|
||||||
|
* @param source the object on which the event initially occurred (never {@code null})
|
||||||
|
* @param logParam login param
|
||||||
|
*/
|
||||||
|
public LogEvent(Object source, LogParam logParam) {
|
||||||
|
super(source);
|
||||||
|
|
||||||
|
// Validate the log param
|
||||||
|
ValidationUtils.validate(logParam);
|
||||||
|
|
||||||
|
this.logParam = logParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LogEvent(Object source, String logKey, LogType logType, String content) {
|
||||||
|
this(source, new LogParam(logKey, logType, content));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LogParam getLogParam() {
|
||||||
|
return logParam;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
package run.halo.app.event.logger;
|
||||||
|
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import run.halo.app.model.entity.Log;
|
||||||
|
import run.halo.app.service.LogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log event listener.
|
||||||
|
*
|
||||||
|
* @author johnniang
|
||||||
|
* @date 19-4-21
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class LogEventListener {
|
||||||
|
|
||||||
|
private final LogService logService;
|
||||||
|
|
||||||
|
public LogEventListener(LogService logService) {
|
||||||
|
this.logService = logService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventListener
|
||||||
|
@Async
|
||||||
|
public void onApplicationEvent(LogEvent event) {
|
||||||
|
// Convert to log
|
||||||
|
Log logToCreate = event.getLogParam().convertTo();
|
||||||
|
// Create log
|
||||||
|
logService.create(logToCreate);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,15 +11,13 @@ import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.event.log.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.event.post.VisitEvent;
|
import run.halo.app.event.post.VisitEvent;
|
||||||
import run.halo.app.exception.AlreadyExistsException;
|
import run.halo.app.exception.AlreadyExistsException;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.exception.NotFoundException;
|
import run.halo.app.exception.NotFoundException;
|
||||||
import run.halo.app.exception.ServiceException;
|
|
||||||
import run.halo.app.model.dto.CategoryOutputDTO;
|
import run.halo.app.model.dto.CategoryOutputDTO;
|
||||||
import run.halo.app.model.dto.TagOutputDTO;
|
import run.halo.app.model.dto.TagOutputDTO;
|
||||||
import run.halo.app.model.dto.post.PostMinimalOutputDTO;
|
import run.halo.app.model.dto.post.PostMinimalOutputDTO;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.cache.StringCacheStore;
|
import run.halo.app.cache.StringCacheStore;
|
||||||
import run.halo.app.event.log.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.exception.NotFoundException;
|
import run.halo.app.exception.NotFoundException;
|
||||||
import run.halo.app.model.entity.User;
|
import run.halo.app.model.entity.User;
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import run.halo.app.event.log.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.model.entity.*;
|
import run.halo.app.model.entity.*;
|
||||||
import run.halo.app.model.enums.AttachmentType;
|
import run.halo.app.model.enums.AttachmentType;
|
||||||
|
|
|
@ -3,8 +3,8 @@ package run.halo.app.event;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import run.halo.app.event.log.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.event.log.LogEventListener;
|
import run.halo.app.event.logger.LogEventListener;
|
||||||
import run.halo.app.utils.ReflectionUtils;
|
import run.halo.app.utils.ReflectionUtils;
|
||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
|
Loading…
Reference in New Issue