Skip to content

felleslosninger/idporten-access-log-spring-boot-starter

Repository files navigation

idporten-access-log-spring-boot-starter

Maven build status Latest Stable Version

This spring boot starter is a library for Tomcat access log (version 9.0.X/10.0.X Tomcat) for Spring Boot project as JSON. See idporten-access-log-spring-boot-3-starter/src/main/resources/logback-access.xml for the syntax of logging.

Requirements

To build and run the application you need:

  • JDK 11
  • Maven

Build library

Build with Maven:

mvn clean install

Usage

The library can be imported through maven with (see latest version under releases):

<dependency>
    <groupId>no.idporten.logging</groupId>
    <artifactId>idporten-access-log-spring-boot-starter</artifactId>
    <version>1.1.1</version>
</dependency>

Or, for Spring Boot 3:

<dependency>
    <groupId>no.idporten.logging</groupId>
    <artifactId>idporten-access-log-spring-boot-3-starter</artifactId>
    <version>2.3.4</version>
</dependency>

Also needs dependency:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-access</artifactId>
</dependency>

And you probably already have included these:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
</dependency>
<dependency>
    <groupId>net.logstash.logback</groupId>
    <artifactId>logstash-logback-encoder</artifactId>
</dependency>
<dependency>
    <groupId>io.opentelemetry.instrumentation</groupId>
    <artifactId>opentelemetry-instrumentation-api</artifactId>
</dependency>

Configuration

The library is configured through the application.yml/yaml or the active spring profile yaml-file.

spring:
  application:
    name: my-application-name
    environment: current-running-environment

The library uses the standard tomcat accesslog property for enabling or disabling logging:

server:
  tomcat:
    accesslog:
      enabled: true # default is true if not set

Use your own logback-access.xml file or configure debug-logging:

digdir:
  access:
    logging:
      debug-level: request # [request|response],  default config if not set or null
      config-file: my-logback.xml # will override debug setting
      filtering:
        static-resources: true # filters out static resources. default is true
        paths: /config.json, /.well-known # comma-separated list of paths to filter out. Matches paths using .startsWith(). Default is empty. 

USE EITHER debug-level OR config-file, not both. Valid values for debug-level are:

  • request: logging attribute fullRequest in addition to normal logging.
  • response: logging attributes fullRequest and fullResponse in addition to normal logging.
  • Use default config if not set or null.

NB: debug-level mode will log very much, use only temporary on servers with not to high load to avoid exhausting central logging-system.

Troubleshooting

If you can not see any access logging in IntelliJ, then try Maven->reload project.