TS11: Add log rotation and change all trace log writes to debug
This commit is contained in:
parent
4be964b537
commit
adb28fdf9f
@ -29,7 +29,7 @@ public class HorseFileDao implements FileDao {
|
||||
throw new IOException("Unsupported file type");
|
||||
|
||||
String fileName = file.getOriginalFilename();
|
||||
LOGGER.trace("Writing file to " + FILE_BASE_PATH + fileName);
|
||||
LOGGER.debug("Writing file to " + FILE_BASE_PATH + fileName);
|
||||
|
||||
try {
|
||||
// Create directory if it doesn't exist
|
||||
@ -45,7 +45,6 @@ public class HorseFileDao implements FileDao {
|
||||
throw new FileSystemException("Base upload directory " + FILE_BASE_PATH + " does not exist");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
throw new IOException("Saving the file failed");
|
||||
}
|
||||
}
|
||||
@ -55,11 +54,10 @@ public class HorseFileDao implements FileDao {
|
||||
if(fileName == null || fileName.equals(""))
|
||||
throw new IOException("Cannot delete an unexisting file");
|
||||
|
||||
LOGGER.trace("Deleting file from " + FILE_BASE_PATH + fileName);
|
||||
LOGGER.debug("Deleting file from " + FILE_BASE_PATH + fileName);
|
||||
try {
|
||||
new File(FILE_BASE_PATH + fileName).delete();
|
||||
} catch(Exception e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
throw new IOException("Deleting the file specified failed");
|
||||
}
|
||||
}
|
||||
@ -69,14 +67,13 @@ public class HorseFileDao implements FileDao {
|
||||
if(fileName == null || fileName.equals(""))
|
||||
throw new IOException("Cannot open an unexisting file");
|
||||
|
||||
LOGGER.trace("Getting file from " + FILE_BASE_PATH + fileName);
|
||||
LOGGER.debug("Getting file from " + FILE_BASE_PATH + fileName);
|
||||
try {
|
||||
// Read the file and return a byte array
|
||||
// https://stackoverflow.com/a/5083666
|
||||
File imageFile = new File(FILE_BASE_PATH + fileName);
|
||||
return Files.readAllBytes(imageFile.toPath());
|
||||
} catch(Exception e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
throw new IOException("Opening the file specified failed");
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class HorseJdbcDao implements HorseDao {
|
||||
|
||||
@Override
|
||||
public Horse findOneById(Long id) {
|
||||
LOGGER.trace("Get horse with id {}", id);
|
||||
LOGGER.debug("Get horse with id {}", id);
|
||||
final String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id=?";
|
||||
List<Horse> horses = jdbcTemplate.query(sql, new Object[] { id }, this::mapRow);
|
||||
|
||||
@ -56,7 +56,7 @@ public class HorseJdbcDao implements HorseDao {
|
||||
|
||||
@Override
|
||||
public List<Horse> getAll() throws NotFoundException {
|
||||
LOGGER.trace("Get all horses");
|
||||
LOGGER.debug("Get all horses");
|
||||
final String sql = "SELECT * FROM " + TABLE_NAME;
|
||||
List<Horse> horses = jdbcTemplate.query(sql, new Object[] { }, this::mapRow);
|
||||
|
||||
@ -67,7 +67,7 @@ public class HorseJdbcDao implements HorseDao {
|
||||
|
||||
@Override
|
||||
public List<Horse> getFiltered(Map<String, String> filters) throws NotFoundException {
|
||||
LOGGER.trace("Get all horses with filters " + filters.entrySet());
|
||||
LOGGER.debug("Get all horses with filters " + filters.entrySet());
|
||||
final String sql = "SELECT * FROM " + TABLE_NAME + " WHERE UPPER(name) LIKE :name AND UPPER(description) LIKE :description AND race LIKE :race AND score LIKE :score AND birthday <= :birthday";
|
||||
|
||||
// Create a list to hold the results
|
||||
@ -112,7 +112,7 @@ public class HorseJdbcDao implements HorseDao {
|
||||
|
||||
@Override
|
||||
public Horse addHorse(Horse horse) throws DataAccessException {
|
||||
LOGGER.trace("Add horse {}", horse.toString());
|
||||
LOGGER.debug("Add horse {}", horse.toString());
|
||||
String sql = "INSERT INTO " + TABLE_NAME + "(name, description, score, birthday, race, image_path, owner_id, created_at, updated_at) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
try {
|
||||
@ -162,7 +162,7 @@ public class HorseJdbcDao implements HorseDao {
|
||||
|
||||
@Override
|
||||
public Horse updateHorse(Horse horse) throws DataAccessException, IOException {
|
||||
LOGGER.trace("Update horse {}", horse.toString());
|
||||
LOGGER.debug("Update horse {}", horse.toString());
|
||||
String sql = "UPDATE " + TABLE_NAME + " SET name=?, description=?, score=?, birthday=?, race=?, image_path=?, owner_id=?, updated_at=? WHERE id=?";
|
||||
|
||||
try {
|
||||
@ -214,7 +214,7 @@ public class HorseJdbcDao implements HorseDao {
|
||||
@Override
|
||||
public void deleteHorse(Long id) throws DataAccessException, NotFoundException, IOException {
|
||||
Horse horseToDelete = this.findOneById(id);
|
||||
LOGGER.trace("Delete horse with id {}", id);
|
||||
LOGGER.debug("Delete horse with id {}", id);
|
||||
final String sql = "DELETE FROM " + TABLE_NAME + " WHERE id=?";
|
||||
|
||||
try {
|
||||
|
@ -47,7 +47,7 @@ public class OwnerJdbcDao implements OwnerDao {
|
||||
|
||||
@Override
|
||||
public Owner findOneById(Long id) {
|
||||
LOGGER.trace("Get owner with id {}", id);
|
||||
LOGGER.debug("Get owner with id {}", id);
|
||||
final String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id=?";
|
||||
List<Owner> owners = jdbcTemplate.query(sql, new Object[] { id }, this::mapRow);
|
||||
|
||||
@ -58,7 +58,7 @@ public class OwnerJdbcDao implements OwnerDao {
|
||||
|
||||
@Override
|
||||
public List<Owner> getAll() throws NotFoundException {
|
||||
LOGGER.trace("Get all owners");
|
||||
LOGGER.debug("Get all owners");
|
||||
final String sql = "SELECT * FROM " + TABLE_NAME;
|
||||
List<Owner> owners = jdbcTemplate.query(sql, new Object[] { }, this::mapRow);
|
||||
|
||||
@ -69,7 +69,7 @@ public class OwnerJdbcDao implements OwnerDao {
|
||||
|
||||
@Override
|
||||
public List<Owner> getFiltered(Map<String, String> filters) throws NotFoundException {
|
||||
LOGGER.trace("Get all owners with filters " + filters.entrySet());
|
||||
LOGGER.debug("Get all owners with filters " + filters.entrySet());
|
||||
final String sql = "SELECT * FROM " + TABLE_NAME + " WHERE UPPER(name) LIKE :name";
|
||||
|
||||
// Create a list to hold the results
|
||||
@ -96,7 +96,7 @@ public class OwnerJdbcDao implements OwnerDao {
|
||||
|
||||
@Override
|
||||
public List<Horse> getOwnedHorses(Long id) throws NotFoundException {
|
||||
LOGGER.trace("Get all horses for owner with id " + id);
|
||||
LOGGER.debug("Get all horses for owner with id " + id);
|
||||
final String sql = "SELECT * FROM " + HORSE_TABLE_NAME + " WHERE owner_id=?";
|
||||
|
||||
List<Horse> horses = jdbcTemplate.query(sql, new Object[] {id}, BeanPropertyRowMapper.newInstance(Horse.class));
|
||||
@ -108,7 +108,7 @@ public class OwnerJdbcDao implements OwnerDao {
|
||||
|
||||
@Override
|
||||
public Owner addOwner(Owner owner) {
|
||||
LOGGER.trace("Add owner {}", owner);
|
||||
LOGGER.debug("Add owner {}", owner);
|
||||
final String sql = "INSERT INTO " + TABLE_NAME + "(name, created_at, updated_at) VALUES(?,?,?)";
|
||||
|
||||
try {
|
||||
@ -147,7 +147,7 @@ public class OwnerJdbcDao implements OwnerDao {
|
||||
|
||||
@Override
|
||||
public Owner updateOwner(Owner owner) throws DataAccessException {
|
||||
LOGGER.trace("Update owner {}", owner.toString());
|
||||
LOGGER.debug("Update owner {}", owner.toString());
|
||||
String sql = "UPDATE " + TABLE_NAME + " SET name=?, updated_at=? WHERE id=?";
|
||||
|
||||
try {
|
||||
@ -186,7 +186,7 @@ public class OwnerJdbcDao implements OwnerDao {
|
||||
@Override
|
||||
public void deleteOwner(Long id) throws DataAccessException, NotFoundException {
|
||||
Owner ownerToDelete = this.findOneById(id);
|
||||
LOGGER.trace("Delete owner with id {}", id);
|
||||
LOGGER.debug("Delete owner with id {}", id);
|
||||
final String sql = "DELETE FROM " + TABLE_NAME + " WHERE id=?";
|
||||
|
||||
if (ownerOwnsHorses(id))
|
||||
|
@ -35,19 +35,19 @@ public class SimpleHorseService implements HorseService {
|
||||
|
||||
@Override
|
||||
public Horse findOneById(Long id) {
|
||||
LOGGER.trace("findOneById({})", id);
|
||||
LOGGER.debug("findOneById({})", id);
|
||||
return horseJdbcDao.findOneById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Horse> getAll() throws NotFoundException {
|
||||
LOGGER.trace("getAll()");
|
||||
LOGGER.debug("getAll()");
|
||||
return horseJdbcDao.getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Horse> getFiltered(Map<String, String> filters) throws NotFoundException, ValidationException {
|
||||
LOGGER.trace("getFiltered({})", filters.entrySet());
|
||||
LOGGER.debug("getFiltered({})", filters.entrySet());
|
||||
this.validator.validateHorseFilter(filters);
|
||||
return horseJdbcDao.getFiltered(filters);
|
||||
}
|
||||
@ -55,34 +55,34 @@ public class SimpleHorseService implements HorseService {
|
||||
@Override
|
||||
public Horse addHorse(Horse horse) throws ValidationException, DataAccessException {
|
||||
this.validator.validateNewHorse(horse);
|
||||
LOGGER.trace("addHorse({})", horse.toString());
|
||||
LOGGER.debug("addHorse({})", horse.toString());
|
||||
return horseJdbcDao.addHorse(horse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Horse updateHorse(Horse horse) throws ValidationException, DataAccessException, IOException {
|
||||
this.validator.validateUpdateHorse(horse);
|
||||
LOGGER.trace("updateHorse({})", horse.toString());
|
||||
LOGGER.debug("updateHorse({})", horse.toString());
|
||||
return horseJdbcDao.updateHorse(horse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteHorse(Long id) throws NotFoundException, DataAccessException, IOException {
|
||||
LOGGER.trace("deleteHorse({})", id);
|
||||
LOGGER.debug("deleteHorse({})", id);
|
||||
horseJdbcDao.deleteHorse(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveImage(MultipartFile img) throws ValidationException, IOException {
|
||||
this.validator.validateHorseImage(img);
|
||||
LOGGER.trace("saveImage({})", img.getName());
|
||||
LOGGER.debug("saveImage({})", img.getName());
|
||||
horseFileDao.save(img);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getImage(String path) throws IOException, ValidationException {
|
||||
this.validator.validateImageRequest(path);
|
||||
LOGGER.trace("getImage({})", path);
|
||||
LOGGER.debug("getImage({})", path);
|
||||
return horseFileDao.get(path);
|
||||
}
|
||||
}
|
||||
|
@ -33,46 +33,46 @@ public class SimpleOwnerService implements OwnerService {
|
||||
|
||||
@Override
|
||||
public Owner findOneById(Long id) {
|
||||
LOGGER.trace("findOneById({})", id);
|
||||
LOGGER.debug("findOneById({})", id);
|
||||
return ownerDao.findOneById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Owner> getAll() throws NotFoundException {
|
||||
LOGGER.trace("getAll()");
|
||||
LOGGER.debug("getAll()");
|
||||
return ownerDao.getAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Owner> getFiltered(Map<String, String> filters) throws NotFoundException, ValidationException {
|
||||
LOGGER.trace("getFiltered({})", filters.entrySet());
|
||||
LOGGER.debug("getFiltered({})", filters.entrySet());
|
||||
this.validator.validateOwnerFilter(filters);
|
||||
return ownerDao.getFiltered(filters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Horse> getOwnedHorses(Long id) throws NotFoundException {
|
||||
LOGGER.trace("getOwnedHorses({})", id);
|
||||
LOGGER.debug("getOwnedHorses({})", id);
|
||||
return ownerDao.getOwnedHorses(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Owner addOwner(Owner owner) throws ValidationException, DataAccessException {
|
||||
LOGGER.trace("addOwner({})", owner);
|
||||
LOGGER.debug("addOwner({})", owner);
|
||||
this.validator.validateNewOwner(owner);
|
||||
return ownerDao.addOwner(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Owner updateOwner(Owner owner) throws ValidationException, DataAccessException {
|
||||
LOGGER.trace("updateOwner({})", owner);
|
||||
LOGGER.debug("updateOwner({})", owner);
|
||||
this.validator.validateUpdateOwner(owner);
|
||||
return ownerDao.updateOwner(owner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteOwner(Long id) throws NotFoundException, DataAccessException {
|
||||
LOGGER.trace("deleteOwner({})", id);
|
||||
LOGGER.debug("deleteOwner({})", id);
|
||||
ownerDao.deleteOwner(id);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
file:
|
||||
name: ./log/wendys-friends.log
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
@ -1,8 +1,6 @@
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
file:
|
||||
name: ./log/wendys-friends.log
|
||||
|
||||
spring:
|
||||
application:
|
||||
|
51
backend/src/main/resources/logback.xml
Normal file
51
backend/src/main/resources/logback.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<configuration>
|
||||
<property name="root.level.console" value="WARN"/>
|
||||
|
||||
<timestamp key="day" datePattern="dd-MM-yyyy"/>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} | %-5level | %40logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<target>System.err</target>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} | %-5level | %40logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} | %-5level | %40logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>
|
||||
log/wendys-friends-%d{dd-MM-yyyy}.log.gz
|
||||
</fileNamePattern>
|
||||
<maxHistory>1</maxHistory>
|
||||
<totalSizeCap>100MB</totalSizeCap>
|
||||
</rollingPolicy>
|
||||
|
||||
</appender>
|
||||
|
||||
<logger name="at.ac.tuwien.sepm.assignment.individual" level="DEBUG" additivity="false">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</logger>
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
|
||||
<root level="ERROR">
|
||||
<appender-ref ref="STDERR"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
</configuration>
|
Reference in New Issue
Block a user