Enonic App Logs to specific file


#1

Hello there,

Guys I’m wondering if does it possible to write logs to a specific file.

Currently, all my logs of my “part1” and “service1” are being stored in home/logs/Server.log. Does it possible that logs of “part1” start to being saved in home/logs/part1.log and the same as “service1”, home/logs/service1.log

This is to organize our server logs split them fin functionality in different files. How can I do that?

Regards,

Soldier.


#2

i’ve too much logs in server.log file and i wish separate that ¿it’s posible? :frowning:


#3

You should use log analyzing tools to separate/query your logs. Check out Elastic for instance.


#4

Well not by part/service, but you can divide by application.
You will need to modify the configuration file “logback.xml”

An example to log all INFO/WARN/ERROR logs from an application “com.enonic.app.myapp” to a file “myapp.log” (in addition to the logging into the console and server.log):

<appender name="MYAPP_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <file>${xp.home}/logs/myapp.log</file>
  <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
    <fileNamePattern>${xp.home}/logs/myapp.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
    <maxFileSize>100MB</maxFileSize>
    <maxHistory>7</maxHistory>
    <totalSizeCap>3GB</totalSizeCap>
  </rollingPolicy>
  <encoder>
    <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
  </encoder>
</appender>

<logger name="com.enonic.app.myapp">
  <level value="INFO" />
  <appender-ref ref="MYAPP_FILE"/>
</logger>

#5

If you do not want to log into server.log, but only in the console and myapp.log, replace the logger part by the one below:

<logger name="com.enonic.app.myapp" additivity="false">
  <level value="INFO" />
  <appender-ref ref="MYAPP_FILE"/>
  <appender-ref ref="STDOUT"/>
</logger>

#6