-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added logging to the contracts microservice
- Loading branch information
1 parent
e436f0f
commit bb4c778
Showing
18 changed files
with
160 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 16 additions & 2 deletions
18
services/contracts/src/main/java/com/workup/contracts/logger/ContractsLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
package com.workup.contracts.logger; | ||
|
||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.core.config.Configurator; | ||
|
||
public class ContractsLogger { | ||
private static final Logger logger = LogManager.getLogger(ContractsLogger.class); | ||
|
||
public static void print(String logMessage, LoggingLevel level) { | ||
Configurator.setRootLevel(Level.ERROR); | ||
|
||
public static void print(String logMessage) { | ||
System.out.println(logMessage); | ||
switch (level) { | ||
case TRACE -> logger.trace("Trace level log message: " + logMessage); | ||
case DEBUG -> logger.debug("Debug level log message: " + logMessage); | ||
case INFO -> logger.info("Info level log message: " + logMessage); | ||
case WARN -> logger.warn("Warn level log message: " + logMessage); | ||
case ERROR -> logger.error("Error level log message: " + logMessage); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
services/contracts/src/main/java/com/workup/contracts/logger/LoggingLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.workup.contracts.logger; | ||
|
||
public enum LoggingLevel { | ||
TRACE, | ||
DEBUG, | ||
INFO, | ||
WARN, | ||
ERROR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<Configuration> | ||
<Properties> | ||
<Property name="baseDir">logs/contracts</Property> | ||
</Properties> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/> | ||
</Console> | ||
|
||
<RollingFile name="AppLogsFileAppender" fileName="${baseDir}/app.log" | ||
filePattern="${baseDir}/app/%d{yyyy}/%d{MM}/%d{dd}/%d{HH:mm:ss}.log.gz"> | ||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/> | ||
<Policies> | ||
<!-- Time-based policy: Rolls daily at midnight --> | ||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/> | ||
<!-- Size-based policy: Rolls after the log file reaches 10 MB --> | ||
<SizeBasedTriggeringPolicy size="10 MB"/> | ||
</Policies> | ||
<DefaultRolloverStrategy max="30"> | ||
<Delete basePath="${baseDir}/app" maxDepth="4"> | ||
<IfFileName glob="/app-.log.gz"/> | ||
<IfLastModified age="30d"/> | ||
</Delete> | ||
</DefaultRolloverStrategy> | ||
<Filters> | ||
<!-- Deny ERROR to avoid duplication in AppLogs --> | ||
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/> | ||
</Filters> | ||
</RollingFile> | ||
|
||
<RollingFile name="ErrorsLogsFileAppender" fileName="${baseDir}/errors.log" | ||
filePattern="${baseDir}/errors/%d{yyyy}/%d{MM}/%d{dd}/%d{HH:mm:ss}.log.gz"> | ||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5level %logger{36} - %msg%n"/> | ||
<Policies> | ||
<!-- Time-based policy: Rolls daily at midnight --> | ||
<TimeBasedTriggeringPolicy interval="1" modulate="true"/> | ||
<!-- Size-based policy: Rolls after the log file reaches 10 MB --> | ||
<SizeBasedTriggeringPolicy size="10 MB"/> | ||
</Policies> | ||
</RollingFile> | ||
|
||
|
||
</Appenders> | ||
|
||
<Loggers> | ||
<Root level="INFO"> | ||
<AppenderRef ref="Console" level="DEBUG"/> | ||
<AppenderRef ref="AppLogsFileAppender"/> | ||
<AppenderRef ref="ErrorsLogsFileAppender" level="ERROR"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |
Oops, something went wrong.