Skip to content

Commit

Permalink
[Tech] fix env for development (#1058)
Browse files Browse the repository at this point in the history
rotation every day
same systemoutput logger for every env
fix rotation dir
  • Loading branch information
thoomasbro authored Dec 12, 2023
2 parents 1d09f65 + 8fda26f commit f74fd08
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Le code source de monitorenv est fortement inspiré de [MonitorFish](https://git
Créer un fichier `./infra/.env` à partir de `./infra/.env.template`
Modifier éventuellement `./infra/configurations/backend/application-dev.properties`

### Sentry

SENTRY_DSN est une variable d'environnement utilisée par Sentry pour identifier l'application. Elle est utilisée par le frontend et le backend. Elle est définie dans le fichier `./infra/.env` et injectée dans l'application frontend via le fichier `./public/env.js`.

Si `SENTRY_DSN` est définie, les logs du backend seront automatiquement envoyés.

## Frontend

`make dev-install` : installation des dépendances du Frontend
Expand Down
20 changes: 5 additions & 15 deletions backend/src/main/resources/log4j2-spring.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
<Configuration packages="org.apache.logging.log4j.core,io.sentry.log4j2">
<Properties>
<!-- This property is user to select the right <Console> -->
<Property name="ENV">${env:SPRING_PROFILES_ACTIVE:-integration}</Property>
<!-- This property is used to activate Sentry only in prod env> -->
<Property name="SENTRY_DSN">${env:SENTRY_DSN:-none}</Property>
</Properties>
<Appenders>
<Console name="dev" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{${sys:PID}}{magenta} [%15.15t] %style{%-40.40C{1.}}{cyan} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
</Console>
<Console name="prod" target="SYSTEM_OUT">
<PatternLayout
pattern="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{${sys:PID}}{magenta} [%15.15t] %style{%-40.40C{1.}}{cyan} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
</Console>
<Console name="integration" target="SYSTEM_OUT" follow="true">
<Console name="ConsoleLogger" target="SYSTEM_OUT" follow="true">
<PatternLayout
pattern="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} %style{${sys:PID}}{magenta} [%15.15t] %style{%-40.40C{1.}}{cyan} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}"/>
</Console>
<Sentry name="Sentry" dsn="${SENTRY_DSN}" />
<!-- Default path is the path within the docker image -->
<!-- This path can be overriden in dev -->
<RollingFile name="Kibana" fileName="${env:BACKEND_LOG_FOLDER:-/home/monitorenv}/logs/kibana.log"
filePattern="/home/monitorenv/logs/${date:yyyy-MM}/kibana-%d{yyyy-MM-dd}-%i.log.gz">
filePattern="${env:BACKEND_LOG_FOLDER:-/home/monitorenv}/logs/${date:yyyy-MM}/kibana-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout pattern="%d{ISO8601} | %-5.5p | %-16.16t | %-32.32c{1} | %-32.32C %4L | %m%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="10MB"/>
</Policies>
<DefaultRolloverStrategy max="31"/>
<TimeBasedTriggeringPolicy />
<TimeBasedTriggeringPolicy interval="24" modulate="true"/>
</RollingFile>
</Appenders>
<Loggers>
<Root level="INFO">
<!-- This <AppenderRef> is used to target the right <Console> -->
<AppenderRef ref="${ENV}"/>
<AppenderRef ref="ConsoleLogger"/>
<AppenderRef ref="Kibana"/>
<AppenderRef ref="Sentry" level="ERROR" />
</Root>
Expand All @@ -49,7 +39,7 @@
<RegexFilter regex=".*(\.svg+|\.png+|\.jpg+|\.js+|\.html+|\.woff2|\.ico).*" onMatch="DENY"
onMismatch="ACCEPT"/>
</Filters>
<AppenderRef ref="${ENV}"/>
<AppenderRef ref="ConsoleLogger"/>
<AppenderRef ref="Kibana"/>
</logger>
</Loggers>
Expand Down
9 changes: 4 additions & 5 deletions infra/configurations/backend/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
monitorenv.server.root=http://localhost:8880
monitorenv.server.port=8880
monitorenv.flyway.locations=classpath:/db/migration,classpath:/db/testdata
# spring.flyway.group=true
# spring.flyway.out-of-order=true

monitorenv.ajp.port=8000
host.ip=localhost:8880

monitorenv.sentry.enabled=false
monitorenv.sentry.environment=dev


###################
# Database settings
#spring.jpa.show-sql=true
# spring.jpa.show-sql=true
# spring.jpa.properties.hibernate.format_sql=true
#logging.level.org.hibernate.orm.jdbc.bind=trace
# logging.level.org.hibernate.orm.jdbc.bind=trace

# Database used by the application (problem with upper case)
env.db.url=jdbc:postgresql://localhost:5432/monitorenvdb?user=postgres&password=postgres

0 comments on commit f74fd08

Please sign in to comment.