Skip to content

devaughns/grails-logging-poc

Repository files navigation

Logging in Grails 4.0.8

Example application demonstrating logging with Grails.
The application will:

  • log an info message every 5 seconds
  • log an error message every 15 seconds

Running the application

To run the application, execute ./gradlew bootRun from the root directory

logback.groovy

The heart of the logging will be accomplished in the grails-app/conf/logback.groovy file. Apart from the imports, everything above line 38 is auto-generated by the command grails create-app.

Setting the HOME_DIR will be the location where you want the logs to reside. In this project, the logs are generated at the root of our application.

def HOME_DIR = "."

We create a new rolling appender

appender("ROLLING", RollingFileAppender) ...

assign a pattern

encoder(PatternLayoutEncoder) {
    pattern = "%level %logger - %msg%n"
}

When assigning a rolling policy we give it 3 arguments

  1. fileNamePattern the pattern of the filename along with the sub-directory where to write them
  2. maxHistory the maximum number of files to retain
  3. totalSizeCap the total size of the log files

Then to utilize the new rolling appender, we need set the logger to ROLLING.

logger('grails.logging', INFO, ['STDOUT', 'ROLLING'], false)

If we wanted all logs instead of just those scoped to grails.logging, we assign the appender as:

root(INFO, ['ROLLING'])

About

POC to show rolling logs within Grails 4.0.8

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published