-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from nhkhai/main
SIS-26: Implemented basic logging.
- Loading branch information
Showing
8 changed files
with
197 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,14 +66,14 @@ jobs: | |
# # Skip tests since they were already run. | ||
# run: mvn package -DskipTests | ||
|
||
- name: Save the Jar file test artifact | ||
- name: Upload the generated application jar file artifact | ||
uses: actions/[email protected] | ||
with: | ||
name: smart-inventory-0.0.1-SNAPSHOT | ||
path: target/smart-inventory-0.0.1-SNAPSHOT.jar | ||
retention-days: 7 | ||
|
||
- name: Upload the test artifacts | ||
- name: Upload the test report artifacts | ||
uses: actions/[email protected] | ||
if: ${{ always() }} | ||
with: | ||
|
@@ -83,11 +83,20 @@ jobs: | |
if-no-files-found: error | ||
retention-days: 7 | ||
|
||
- name: Upload the HTML report test artifacts | ||
- name: Upload the HTML test report artifacts | ||
uses: actions/[email protected] | ||
if: ${{ always() }} | ||
with: | ||
name: html-test-report | ||
path: "**/target/site/**" | ||
if-no-files-found: error | ||
retention-days: 7 | ||
|
||
- name: Upload the application and test log file artifacts | ||
uses: actions/[email protected] | ||
if: ${{ always() }} | ||
with: | ||
name: application-and-test-logs | ||
path: "**/logs/**" | ||
if-no-files-found: error | ||
retention-days: 7 |
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 |
---|---|---|
|
@@ -31,4 +31,7 @@ build/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Generated Log Files ### | ||
src/main/java/sg/com/smartinventory/logfile | ||
logs/** |
10 changes: 10 additions & 0 deletions
10
src/main/java/sg/com/smartinventory/SmartInventoryApplication.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,11 +1,21 @@ | ||
package sg.com.smartinventory; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class SmartInventoryApplication { | ||
// Name this according to your class name. | ||
private static final Logger app_logger = LoggerFactory.getLogger(SmartInventoryApplication.class); | ||
|
||
public static void main(String[] args) { | ||
app_logger.info("Starting SmartInventoryApplication. "); | ||
|
||
SpringApplication.run(SmartInventoryApplication.class, args); | ||
|
||
app_logger.info("Exiting SmartInventoryApplication. "); | ||
} | ||
} |
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,68 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<!-- Define a common variable --> | ||
<property name="AppLogPath" value="./logs" /> | ||
<!-- Define a Console Appender --> | ||
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- Define the log message format --> | ||
<encoder> | ||
<pattern> | ||
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n | ||
</pattern> | ||
</encoder> | ||
</appender> | ||
<!-- Define a Console2 Appender --> | ||
<appender name="Console2" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- Define the log message format --> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
<pattern> | ||
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): | ||
%msg%n%throwable | ||
</pattern> | ||
</layout> | ||
</appender> | ||
<!-- Define a File Appender --> | ||
<appender name="File" class="ch.qos.logback.core.FileAppender"> | ||
<!-- Specify path to log file --> | ||
<!-- <file>logs/application.log</file> --> | ||
<file>${AppLogPath}/application.log</file> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<appender name="RollingFile" | ||
class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<file>${AppLogPath}/application.log</file> | ||
<encoder | ||
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
<pattern>%d %p %C{1.} [%t] %m%n</pattern> | ||
</encoder> | ||
<rollingPolicy | ||
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
<!-- Rollover daily and when the file reaches 10 MegaBytes --> | ||
<fileNamePattern>${AppLogPath}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log | ||
</fileNamePattern> | ||
<timeBasedFileNamingAndTriggeringPolicy | ||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> | ||
<maxFileSize>10MB</maxFileSize> | ||
</timeBasedFileNamingAndTriggeringPolicy> | ||
</rollingPolicy> | ||
</appender> | ||
<!-- Set root log level to "INFO" --> | ||
<root level="info"> | ||
<!-- Reference the "Console" appender for console output --> | ||
<appender-ref ref="Console" /> | ||
<!-- <appender-ref ref="Console2" /> --> | ||
<!-- Reference the "File" appender for file output --> | ||
<appender-ref ref="File" /> | ||
<!-- Reference the "RollingFile" appender for file output --> | ||
<!-- <appender-ref ref="RollingFile" /> --> | ||
</root> | ||
<!-- LOG "sg.com.smartinventory*" at "TRACE" level --> | ||
<!-- | ||
<logger name="sg.com.smartinventory" level="trace" additivity="false"> | ||
<appender-ref ref="RollingFile" /> | ||
<appender-ref ref="Console" /> | ||
</logger> | ||
--> | ||
</configuration> |
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,6 @@ | ||
# Test logging configuration. | ||
# logging.config=classpath:logback-testloglevel.xml | ||
|
||
# Add a Spring profile to our test by using the ActiveProfiles annotation, for example @ActiveProfiles("logging-test"). | ||
# logging.level.sg.com.smartinventory.testloglevel=TRACE | ||
# logging.level.root=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<configuration> | ||
<include resource="/org/springframework/boot/logging/logback/base.xml" /> | ||
<!-- Define a common variable --> | ||
<property name="TestLogPath" value="./logs" /> | ||
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- Define the log message format --> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n | ||
</pattern> | ||
</encoder> | ||
</appender> | ||
<appender name="Console2" class="ch.qos.logback.core.ConsoleAppender"> | ||
<!-- Define the log message format --> | ||
<layout class="ch.qos.logback.classic.PatternLayout"> | ||
<pattern> | ||
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): | ||
%msg%n%throwable | ||
</pattern> | ||
</layout> | ||
</appender> | ||
<!-- Define a File Appender --> | ||
<appender name="File" class="ch.qos.logback.core.FileAppender"> | ||
<!-- Specify path to log file --> | ||
<!-- <file>logs/test.log</file> --> | ||
<file>${TestLogPath}/test.log</file> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<appender name="RollingFile" | ||
class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<file>${TestLogPath}/test.log</file> | ||
<encoder | ||
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
<pattern>%d %p %C{1.} [%t] %m%n</pattern> | ||
</encoder> | ||
<rollingPolicy | ||
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
<!-- Rollover daily and when the file reaches 10 MegaBytes --> | ||
<fileNamePattern>${TestLogPath}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log | ||
</fileNamePattern> | ||
<timeBasedFileNamingAndTriggeringPolicy | ||
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> | ||
<maxFileSize>10MB</maxFileSize> | ||
</timeBasedFileNamingAndTriggeringPolicy> | ||
</rollingPolicy> | ||
</appender> | ||
<!-- Set root log level to "ERROR" --> | ||
<root level="error"> | ||
<!-- Reference the "Console" appender for console output --> | ||
<appender-ref ref="Console" /> | ||
<!-- <appender-ref ref="Console2" /> --> | ||
<!-- Reference the "File" appender for file output --> | ||
<appender-ref ref="File" /> | ||
<!-- Reference the "RollingFile" appender for file output --> | ||
<!-- <appender-ref ref="RollingFile" /> --> | ||
</root> | ||
<logger name="sg.com.smartinventory.testloglevel" level="debug" /> | ||
<!-- | ||
<springProfile name="logback-test1"> | ||
<logger name="sg.com.smartinventory.testloglevel" level="info" /> | ||
</springProfile> | ||
<springProfile name="logback-test2"> | ||
<logger name="sg.com.smartinventory.testloglevel" level="trace" /> | ||
</springProfile> | ||
--> | ||
</configuration> |