<commit_before># Dockerized Logrotate

[![Docker Stars](https://img.shields.io/docker/stars/blacklabelops/logrotate.svg)](https://hub.docker.com/r/blacklabelops/logrotate/) [![Docker Pulls](https://img.shields.io/docker/pulls/blacklabelops/logrotate.svg)](https://hub.docker.com/r/blacklabelops/logrotate/) [![](https://badge.imagelayers.io/blacklabelops/logrotate:latest.svg)](https://imagelayers.io/?images=blacklabelops/logrotate:latest 'Get your own badge on imagelayers.io')

This container can crawl for logfiles and rotate them. It is a side-car container
for containers that write logfiles and need a log rotation mechanism. Just hook up some containers and define your
backup volumes.

# Make It Short

In short, this container can rotate all your Docker logfiles just by typing:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  blacklabelops/logrotate
~~~~

> This will rotate all your Docker logfiles on a daily basis up to 5 times.

You want to do it hourly? Just type:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_INTERVAL=hourly" \
  blacklabelops/logrotate
~~~~

> This will put logrotate on an hourly schedule.

# How To Attach to Logs

In order to attach the side-car container to your logs you have to hook your log file folders inside volumes. Afterwards
specify the folders logrotate should crawl for log files. The container attaches by default to any file ending with **.log** inside the specified folders.

Environment variable for specifying log folders: `LOGS_DIRECTORIES`. Each directory must be separated by a whitespace character.

Example:

~~~~
LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker
~~~~

Example Logrotating all Docker logfiles:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  blacklabelops/logrotate
~~~~

> This will logrotate any logfile(s) under /var/lib/docker/containers, /var/log/docker (or subdirectories of them).

# Customize Log File Ending

You can define the file endings fluentd will attach to. The container will by default crawl for
files ending with **.log**. This can be overriden and extended to any amount of file endings.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOG_FILE_ENDINGS=json xml" \
  blacklabelops/logrotate
~~~~

> Crawls for file endings .json and .xml.

# Set the Log interval

Logrotate can rotate logfile according to the following intervals:

* `hourly`
* `daily`
* `weekly`
* `monthly`
* `yearly`

You can override the default setting with the environment variable `LOGROTATE_INTERVAL`.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_INTERVAL=hourly" \
  blacklabelops/logrotate
~~~~

> This will logrotate logfile(s) on hourly basis.

# Set the Number of Rotations

The default number of rotations is five. Further rotations will delete old logfiles. You
can override the default setting with the environment variable `LOGROTATE_COPIES`.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_COPIES=10" \
  blacklabelops/logrotate
~~~~

> Will create 10 daily logs before deleting old logs.

# Set Maximum File size

Logrotate can do additional rotates, when the logfile exceeds a certain file size. You can specifiy file size rotation
with the environment variable `LOGROTATE_SIZE`.

Valid example values:

* `100k`: Will rotate when log file exceeds 100 kilobytes.
* `100M`: Will rotate when log file exceeds 100 Megabytes.
* `100G`: Will rotate when log file exceeds 100 Gigabytes.

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_SIZE=10M" \
  blacklabelops/logrotate
~~~~

> This will logrotate when logfile(s) reaches 10M+.

# Set Log File compression

The default logrotate setting is `nocompress`. In order to enable logfile compression
you can set the environment variable `LOGROTATE_COMPRESSION` to `compress`.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_COMPRESSION=compress" \
  blacklabelops/logrotate
~~~~

> This will compress the logrotated logs.

# Set the Output directory

By default, logrotate will rotate logs in their respective directories. You can
specify a directory for keeping old logfiles with the environment variable `LOGROTATE_OLDDIR`. You can specify a full or relative path.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -v $(pwd)/logs:/logs/ \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_OLDDIR=/logs" \
  blacklabelops/logrotate
~~~~

> Will move old logfiles in the local directory logs/.

# Set the Cron Schedule

You can set the cron schedule independently of the logrotate interval. You can override
the default schedule with the enviroment variable `LOGROTATE_CRONSCHEDULE`.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_INTERVAL=hourly" \
  -e "LOGROTATE_CRONSCHEDULE=* * * * * *" \
  blacklabelops/logrotate
~~~~

> This will logrotate on go-cron schedule "* * * * * *" (every second).

# Log and View the Logrotate Output

You can specify a logfile for the periodical logrotate execution. The file
is specified using the environment variable `LOGROTATE_LOGFILE`. Must be a full path!

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -v $(pwd)/logs:/logs \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_INTERVAL=hourly" \
  -e "LOGROTATE_CRONSCHEDULE=* * * * * *" \
  -e "LOGROTATE_LOGFILE=/logs/logrotatecron.log" \
  blacklabelops/logrotate
~~~~

> You will be able to see logrotate output every minute in file logs/logrotatecron.log.

# Logrotate Commandline Parameters

You can define the logrotate commandline parameters with the environment variable LOGROTATE_PARAMETERS.

*v*: Verbose

*d*: Debug, Logrotate will be emulated but never executed!<commit_msg>update README.md, fix markdown cron schedule section<commit_after># Dockerized Logrotate

[![Docker Stars](https://img.shields.io/docker/stars/blacklabelops/logrotate.svg)](https://hub.docker.com/r/blacklabelops/logrotate/) [![Docker Pulls](https://img.shields.io/docker/pulls/blacklabelops/logrotate.svg)](https://hub.docker.com/r/blacklabelops/logrotate/) [![](https://badge.imagelayers.io/blacklabelops/logrotate:latest.svg)](https://imagelayers.io/?images=blacklabelops/logrotate:latest 'Get your own badge on imagelayers.io')

This container can crawl for logfiles and rotate them. It is a side-car container
for containers that write logfiles and need a log rotation mechanism. Just hook up some containers and define your
backup volumes.

# Make It Short

In short, this container can rotate all your Docker logfiles just by typing:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  blacklabelops/logrotate
~~~~

> This will rotate all your Docker logfiles on a daily basis up to 5 times.

You want to do it hourly? Just type:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_INTERVAL=hourly" \
  blacklabelops/logrotate
~~~~

> This will put logrotate on an hourly schedule.

# How To Attach to Logs

In order to attach the side-car container to your logs you have to hook your log file folders inside volumes. Afterwards
specify the folders logrotate should crawl for log files. The container attaches by default to any file ending with **.log** inside the specified folders.

Environment variable for specifying log folders: `LOGS_DIRECTORIES`. Each directory must be separated by a whitespace character.

Example:

~~~~
LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker
~~~~

Example Logrotating all Docker logfiles:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  blacklabelops/logrotate
~~~~

> This will logrotate any logfile(s) under /var/lib/docker/containers, /var/log/docker (or subdirectories of them).

# Customize Log File Ending

You can define the file endings fluentd will attach to. The container will by default crawl for
files ending with **.log**. This can be overriden and extended to any amount of file endings.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOG_FILE_ENDINGS=json xml" \
  blacklabelops/logrotate
~~~~

> Crawls for file endings .json and .xml.

# Set the Log interval

Logrotate can rotate logfile according to the following intervals:

* `hourly`
* `daily`
* `weekly`
* `monthly`
* `yearly`

You can override the default setting with the environment variable `LOGROTATE_INTERVAL`.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_INTERVAL=hourly" \
  blacklabelops/logrotate
~~~~

> This will logrotate logfile(s) on hourly basis.

# Set the Number of Rotations

The default number of rotations is five. Further rotations will delete old logfiles. You
can override the default setting with the environment variable `LOGROTATE_COPIES`.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_COPIES=10" \
  blacklabelops/logrotate
~~~~

> Will create 10 daily logs before deleting old logs.

# Set Maximum File size

Logrotate can do additional rotates, when the logfile exceeds a certain file size. You can specifiy file size rotation
with the environment variable `LOGROTATE_SIZE`.

Valid example values:

* `100k`: Will rotate when log file exceeds 100 kilobytes.
* `100M`: Will rotate when log file exceeds 100 Megabytes.
* `100G`: Will rotate when log file exceeds 100 Gigabytes.

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_SIZE=10M" \
  blacklabelops/logrotate
~~~~

> This will logrotate when logfile(s) reaches 10M+.

# Set Log File compression

The default logrotate setting is `nocompress`. In order to enable logfile compression
you can set the environment variable `LOGROTATE_COMPRESSION` to `compress`.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_COMPRESSION=compress" \
  blacklabelops/logrotate
~~~~

> This will compress the logrotated logs.

# Set the Output directory

By default, logrotate will rotate logs in their respective directories. You can
specify a directory for keeping old logfiles with the environment variable `LOGROTATE_OLDDIR`. You can specify a full or relative path.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -v $(pwd)/logs:/logs/ \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_OLDDIR=/logs" \
  blacklabelops/logrotate
~~~~

> Will move old logfiles in the local directory logs/.

# Set the Cron Schedule

You can set the cron schedule independently of the logrotate interval. You can override
the default schedule with the enviroment variable `LOGROTATE_CRONSCHEDULE`.

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_INTERVAL=hourly" \
  -e "LOGROTATE_CRONSCHEDULE=* * * * * *" \
  blacklabelops/logrotate
~~~~

> This will logrotate on go-cron schedule \* \* \* \* \* \* (every second).

# Log and View the Logrotate Output

You can specify a logfile for the periodical logrotate execution. The file
is specified using the environment variable `LOGROTATE_LOGFILE`. Must be a full path!

Example:

~~~~
$ docker run -d \
  -v /var/lib/docker/containers:/var/lib/docker/containers \
  -v /var/log/docker:/var/log/docker \
  -v $(pwd)/logs:/logs \
  -e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
  -e "LOGROTATE_INTERVAL=hourly" \
  -e "LOGROTATE_CRONSCHEDULE=* * * * * *" \
  -e "LOGROTATE_LOGFILE=/logs/logrotatecron.log" \
  blacklabelops/logrotate
~~~~

> You will be able to see logrotate output every minute in file logs/logrotatecron.log.

# Logrotate Commandline Parameters

You can define the logrotate commandline parameters with the environment variable LOGROTATE_PARAMETERS.

*v*: Verbose

*d*: Debug, Logrotate will be emulated but never executed!
{'fraction_non_alphanumeric': 0.11979849561796978, 'fraction_numerical': 0.0037264509005589678, 'mean_word_length': 3.8146179401993354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4951454', 'n_tokens_mistral': 5151, 'n_tokens_neox': 4751, 'n_words': 1407}