Skip to content

Latest commit

 

History

History
105 lines (79 loc) · 2.58 KB

File metadata and controls

105 lines (79 loc) · 2.58 KB

CoffeeNet Starter - Logging

This CoffeeNet starter configures a consistent logging format and behaviour through all of your CoffeeNet applications.

Getting started

This is a module in the starter set, so you first need to declare your project as a child of the starter parent by editing the pom.xml file.

<parent>
    <groupId>rocks.coffeenet</groupId>
    <artifactId>coffeenet-starter-parent</artifactId>
    <version>${parent.version}</version>
    <relativePath />
</parent>

Now you can enable logging in your project, by first adding the dependency:

<dependency>
    <groupId>rocks.coffeenet</groupId>
    <artifactId>coffeenet-starter-logging</artifactId>
</dependency>

In order to get everything up and running there are some requirements that your project must fulfill.

Usage

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.invoke.MethodHandles;

public class LoggingClass {

  private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
  ...
}

Configuration

The logging starter configuration depends on the CoffeeNet profile coffeenet.profile.

But it is possible to change the configuration, independent of the chosen profile `developmentorintegration``` at any time and remove or add specific appenders.

coffeenet:
  application-name:
  profile: development
  logging:
    enabled: true
    console:
      enabled:
    file:
      enabled:
      file: logs/app.log
      max-history: 30
      file-name-pattern: logs/app-%d{yyyy-MM-dd}.log
      pattern: '%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%t] %-40.40logger{39} : %m%n%wEx'
    gelf:
      enabled:
      server: localhost
      port: 12201
      protocol: UDP
      environment:
      layout: '%m %n'

The coffeenet.application-name will be used to identify the application when logging into the Graylog server.

If you want to change the logging level for packages for example, then you can use the default spring behaviour

logging:
  level:
    rocks.coffeenet: ${LogLevel}
    rocks.coffeenet.auth: ${LogLevel}
    ...

Development

Is the coffeenet.profile set to development by default:

  • the console appender will be activated
  • the file appender will be deactivated
  • the gelf (Graylog Extended Log Format) appender will be deactivated

Integration

Is the coffeenet.profile set to integration by default:

  • the console appender will be deactivated
  • the file appender will be activated
  • the gelf (Graylog Extended Log Format) appender will be activated