diff --git a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseFileDao.java b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseFileDao.java index df9d97b..a8bb070 100644 --- a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseFileDao.java +++ b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseFileDao.java @@ -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"); } } diff --git a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java index 616fdfd..4b468ee 100644 --- a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java +++ b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/HorseJdbcDao.java @@ -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 horses = jdbcTemplate.query(sql, new Object[] { id }, this::mapRow); @@ -56,7 +56,7 @@ public class HorseJdbcDao implements HorseDao { @Override public List getAll() throws NotFoundException { - LOGGER.trace("Get all horses"); + LOGGER.debug("Get all horses"); final String sql = "SELECT * FROM " + TABLE_NAME; List horses = jdbcTemplate.query(sql, new Object[] { }, this::mapRow); @@ -67,7 +67,7 @@ public class HorseJdbcDao implements HorseDao { @Override public List getFiltered(Map 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 { diff --git a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/OwnerJdbcDao.java b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/OwnerJdbcDao.java index a0f0b42..4564edc 100644 --- a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/OwnerJdbcDao.java +++ b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/persistence/impl/OwnerJdbcDao.java @@ -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 owners = jdbcTemplate.query(sql, new Object[] { id }, this::mapRow); @@ -58,7 +58,7 @@ public class OwnerJdbcDao implements OwnerDao { @Override public List getAll() throws NotFoundException { - LOGGER.trace("Get all owners"); + LOGGER.debug("Get all owners"); final String sql = "SELECT * FROM " + TABLE_NAME; List owners = jdbcTemplate.query(sql, new Object[] { }, this::mapRow); @@ -69,7 +69,7 @@ public class OwnerJdbcDao implements OwnerDao { @Override public List getFiltered(Map 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 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 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)) diff --git a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java index 6f66ed6..39c8274 100644 --- a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java +++ b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleHorseService.java @@ -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 getAll() throws NotFoundException { - LOGGER.trace("getAll()"); + LOGGER.debug("getAll()"); return horseJdbcDao.getAll(); } @Override public List getFiltered(Map 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); } } diff --git a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleOwnerService.java b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleOwnerService.java index e4ebe8b..41f0926 100644 --- a/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleOwnerService.java +++ b/backend/src/main/java/at/ac/tuwien/sepm/assignment/individual/service/impl/SimpleOwnerService.java @@ -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 getAll() throws NotFoundException { - LOGGER.trace("getAll()"); + LOGGER.debug("getAll()"); return ownerDao.getAll(); } @Override public List getFiltered(Map 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 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); } } diff --git a/backend/src/main/resources/application-test.yml b/backend/src/main/resources/application-test.yml index b50b7fc..a190690 100644 --- a/backend/src/main/resources/application-test.yml +++ b/backend/src/main/resources/application-test.yml @@ -1,8 +1,6 @@ logging: level: root: INFO - file: - name: ./log/wendys-friends.log spring: application: diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 8405084..e25b6c7 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -1,8 +1,6 @@ logging: level: root: INFO - file: - name: ./log/wendys-friends.log spring: application: diff --git a/backend/src/main/resources/logback.xml b/backend/src/main/resources/logback.xml new file mode 100644 index 0000000..acb03f8 --- /dev/null +++ b/backend/src/main/resources/logback.xml @@ -0,0 +1,51 @@ + + + + + + + + %d{HH:mm:ss.SSS} | %-5level | %40logger{0}: %msg%n + + + + + System.err + + ERROR + + + %d{HH:mm:ss.SSS} | %-5level | %40logger{0}: %msg%n + + + + + + %d{HH:mm:ss.SSS} | %-5level | %40logger{0}: %msg%n + + + + + log/wendys-friends-%d{dd-MM-yyyy}.log.gz + + 1 + 100MB + + + + + + + + + + + + + + + + + + +