| 1 | package org.europa.together.service; | |
| 2 | ||
| 3 | import java.io.File; | |
| 4 | import java.io.IOException; | |
| 5 | import java.nio.file.Files; | |
| 6 | import java.nio.file.Paths; | |
| 7 | import java.nio.file.StandardCopyOption; | |
| 8 | import org.apiguardian.api.API; | |
| 9 | import static org.apiguardian.api.API.Status.STABLE; | |
| 10 | import org.europa.together.application.LogbackLogger; | |
| 11 | import org.europa.together.application.SaxTools; | |
| 12 | import org.europa.together.business.Logger; | |
| 13 | import org.europa.together.business.XmlTools; | |
| 14 | import org.europa.together.domain.LogLevel; | |
| 15 | import org.europa.together.utils.Constraints; | |
| 16 | import org.europa.together.utils.FileUtils; | |
| 17 | import org.springframework.stereotype.Service; | |
| 18 | ||
| 19 | /** | |
| 20 | * Service implementation for the LogbackLogger. | |
| 21 | * | |
| 22 | * @author elmar.dott@gmail.com | |
| 23 | * @version 1.0 | |
| 24 | * @since 1.0 | |
| 25 | */ | |
| 26 | @API(status = STABLE, since = "1.1") | |
| 27 | @Service | |
| 28 | public final class LoggingService { | |
| 29 | ||
| 30 | private static final long serialVersionUID = 201L; | |
| 31 | private static final Logger LOGGER = new LogbackLogger(LoggingService.class); | |
| 32 | ||
| 33 | /** | |
| 34 | * Constructor. | |
| 35 | */ | |
| 36 | @API(status = STABLE, since = "1.1") | |
| 37 | public LoggingService() { | |
| 38 | LOGGER.log("instance class", LogLevel.INFO); | |
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * Creates for an application a external log configuration. Copy the | |
| 43 | * configuration file for the Logger from the classpath to the application | |
| 44 | * directory. | |
| 45 | * | |
| 46 | * @throws java.io.IOException case of error | |
| 47 | */ | |
| 48 | @API(status = STABLE, since = "1.1") | |
| 49 | public void createLogConfiguration() throws IOException { | |
| 50 | String destination = Constraints.SYSTEM_APP_DIR + "/logback.xml"; | |
| 51 | LOGGER.log("Copy File to: " + destination, LogLevel.DEBUG); | |
| 52 | ||
| 53 | Files.copy(getClass().getClassLoader() | |
| 54 | .getResourceAsStream("org/europa/together/configuration/logback.xml"), | |
| 55 | Paths.get(destination), StandardCopyOption.REPLACE_EXISTING); | |
| 56 | } | |
| 57 | ||
| 58 | /** | |
| 59 | * Read the log configuration from a file and return the file content. | |
| 60 | * | |
| 61 | * @param file as String | |
| 62 | * @return configuration as String | |
| 63 | * @throws java.io.IOException case of error | |
| 64 | */ | |
| 65 | @API(status = STABLE, since = "1.1") | |
| 66 | public String readLogConfiguration(final String file) | |
| 67 | throws IOException { | |
| 68 | String configuration = null; | |
| 69 | configuration = FileUtils.readFileStream(new File(file)); | |
| 70 |
1
1. readLogConfiguration : replaced return value with "" for org/europa/together/service/LoggingService::readLogConfiguration → SURVIVED |
return configuration; |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Write a configuration to a file. The file will only written when the XML | |
| 75 | * is well formed. | |
| 76 | * | |
| 77 | * @param content as String | |
| 78 | * @param file as String | |
| 79 | * @throws java.io.IOException case of error | |
| 80 | */ | |
| 81 | @API(status = STABLE, since = "1.1") | |
| 82 | public void writeLogConfiguration(final String content, final String file) | |
| 83 | throws IOException { | |
| 84 | XmlTools xmlTools = new SaxTools(); | |
| 85 | xmlTools.parseXmlString(content); | |
| 86 | LOGGER.log("try to update logger configuration to: " + file, LogLevel.DEBUG); | |
| 87 |
1
1. writeLogConfiguration : negated conditional → KILLED |
if (!xmlTools.isWellFormed()) { |
| 88 | throw new IOException("xml is not wellformed, file can not updated."); | |
| 89 | } else { | |
| 90 |
1
1. writeLogConfiguration : removed call to org/europa/together/business/XmlTools::writeXmlToFile → SURVIVED |
xmlTools.writeXmlToFile(xmlTools.prettyPrintXml(), file); |
| 91 | } | |
| 92 | } | |
| 93 | } | |
Mutations | ||
| 70 |
1.1 |
|
| 87 |
1.1 |
|
| 90 |
1.1 |