Skip to content

Commit

Permalink
feat(log): add backend log rolling file strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
guzhongren authored and BoBoDai committed Dec 21, 2023
1 parent 33e3f22 commit f82ced8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ out/

### VS Code ###
.vscode/

logs
23 changes: 16 additions & 7 deletions backend/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Configuration status="INFO" name="Heartbeat">
<Properties>
<Property name="LOG_PATTERN">
%d{yyyy-MM-dd HH:mm:ss.SSS} [%highlight{%-5level}{FATAL=bg_red, ERROR=red, WARN=yellow, INFO=green}] [%t] %M(%c{1}:%L): %m%n%ex
</Property>
</Properties>

<Appenders>
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
<RollingFile name="RollingFile" fileName="logs/Heartbeat.log"
filePattern="logs/Heartbeat-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>

<Loggers>
<Root level="info">
<AppenderRef ref="RollingFile"/>
<AppenderRef ref="ConsoleAppender"/>
</Root>
</Loggers>
</Configuration>
</Configuration>
1 change: 1 addition & 0 deletions ops/infra/Dockerfile.backend
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ LABEL app=Heartbeat
LABEL arch=Backend
RUN groupadd -r nonroot && useradd --no-log-init -r -g nonroot nonroot
RUN mkdir -p ./csv && chown -R nonroot:nonroot ./csv
RUN mkdir -p ./logs && chown -R nonroot:nonroot ./logs
USER nonroot

EXPOSE 4322
Expand Down

0 comments on commit f82ced8

Please sign in to comment.