| 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 |
|
|
| 21 |
|
|
| 22 |
|
@author |
| 23 |
|
@version |
| 24 |
|
@since |
| 25 |
|
|
| 26 |
|
@API(status = STABLE, since = "1.1") |
| 27 |
|
@Service |
| |
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 5 |
Complexity Density: 0.38 |
|
| 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 |
|
|
| 35 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 36 |
2 |
@API(status = STABLE, since = "1.1")... |
| 37 |
|
public LoggingService() { |
| 38 |
2 |
LOGGER.log("instance class", LogLevel.INFO); |
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
@throws |
| 47 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 48 |
1 |
@API(status = STABLE, since = "1.1")... |
| 49 |
|
public void createLogConfiguration() throws IOException { |
| 50 |
1 |
String destination = Constraints.SYSTEM_APP_DIR + "/logback.xml"; |
| 51 |
1 |
LOGGER.log("Copy File to: " + destination, LogLevel.DEBUG); |
| 52 |
|
|
| 53 |
1 |
Files.copy(getClass().getClassLoader() |
| 54 |
|
.getResourceAsStream("org/europa/together/configuration/logback.xml"), |
| 55 |
|
Paths.get(destination), StandardCopyOption.REPLACE_EXISTING); |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@param |
| 62 |
|
@return |
| 63 |
|
@throws |
| 64 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 65 |
2 |
@API(status = STABLE, since = "1.1")... |
| 66 |
|
public String readLogConfiguration(final String file) |
| 67 |
|
throws IOException { |
| 68 |
2 |
String configuration = null; |
| 69 |
2 |
configuration = FileUtils.readFileStream(new File(file)); |
| 70 |
1 |
return configuration; |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
@param |
| 78 |
|
@param |
| 79 |
|
@throws |
| 80 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 81 |
2 |
@API(status = STABLE, since = "1.1")... |
| 82 |
|
public void writeLogConfiguration(final String content, final String file) |
| 83 |
|
throws IOException { |
| 84 |
2 |
XmlTools xmlTools = new SaxTools(); |
| 85 |
2 |
xmlTools.parseXmlString(content); |
| 86 |
2 |
LOGGER.log("try to update logger configuration to: " + file, LogLevel.DEBUG); |
| 87 |
2 |
if (!xmlTools.isWellFormed()) { |
| 88 |
1 |
throw new IOException("xml is not wellformed, file can not updated."); |
| 89 |
|
} else { |
| 90 |
1 |
xmlTools.writeXmlToFile(xmlTools.prettyPrintXml(), file); |
| 91 |
|
} |
| 92 |
|
} |
| 93 |
|
} |