Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conf/logback.xml: Rotate logs #62

Closed
ilyaglow opened this issue Feb 7, 2018 · 2 comments
Closed

conf/logback.xml: Rotate logs #62

ilyaglow opened this issue Feb 7, 2018 · 2 comments
Assignees
Labels
Milestone

Comments

@ilyaglow
Copy link

ilyaglow commented Feb 7, 2018

Rotate logs

Request Type

Feature Request

Problem Description

Hey there,

Currently Cortex do not limit application.log file size, so it can became really huge, causing Cortex to freeze when no free space left (this is especially a Docker version problem).

Possible Solutions

This is the solution that I came so far, inspired by the following gist: https://gist.github.com/jcraane/5921329

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">

	<conversionRule conversionWord="coloredLevel"
		converterClass="play.api.libs.logback.ColoredLevel" />

	<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${application.home:-.}/logs/application.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${application.home:-.}/logs/application_%d{yyyy-MM-dd}.%i.log</fileNamePattern>

            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>10MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>30</maxHistory>
        </rollingPolicy>
	<encoder>
		<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern>
	</encoder>
	</appender>

	<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>%coloredLevel %logger{15} - %message%n%xException{10}
			</pattern>
		</encoder>
	</appender>

	<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender">
		<appender-ref ref="FILE" />
	</appender>

	<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender">
		<appender-ref ref="STDOUT" />
	</appender>

	<logger name="play" level="INFO" />
	<logger name="application" level="INFO" />

	<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />

	<root level="INFO">
		<appender-ref ref="ASYNCFILE" />
		<appender-ref ref="ASYNCSTDOUT" />
	</root>

</configuration>

It will rotate log every day and set the maximum size of it to 10MB. Max history time is set to 30 days.

What do you think?

@nadouani
Copy link
Contributor

nadouani commented Feb 7, 2018

Yes, this is valid for both Cortex and TheHive. The default logback.xml file we ship with the packages doesn't enable log rotation, we should probably add a section about this on the FAQ.

Thanks for sharing

@nadouani nadouani added the doc label Feb 7, 2018
@To-om To-om self-assigned this May 14, 2018
@To-om To-om added this to the 2.1.3 milestone Dec 19, 2018
To-om added a commit that referenced this issue Dec 19, 2018
@To-om To-om closed this as completed Dec 19, 2018
@suv1sh
Copy link

suv1sh commented Jan 14, 2020

what if I want to only rotate the logs only after it reaches a certain size let say 5MB and it gets saved in archive directory and again it starts rotating the logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants