Skip to content

Eclipse Logging with Logback

Raymond Augé edited this page Jun 2, 2020 · 2 revisions

When using Eclipse with M2E a global logback config file can be used to provide tuneable logging configuration for all workspaces.

Configuring a global logback config

  • edit the eclipse.ini file in the Eclipse installation directory

  • add the system property -Dlogback.configurationFile= and set the value to a shared configuration file e.g. -Dlogback.configurationFile=file:/home/me/bin/eclipse.logback.xml

  • set the initial contents of this file to something like:

    <configuration scan="true">
      <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
          <pattern>%date [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
      </appender>
      <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${osgi.logfile}-0-back.log</File>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
          <FileNamePattern>${osgi.logfile}-%i-back.log</FileNamePattern>
          <MinIndex>1</MinIndex>
          <MaxIndex>10</MaxIndex>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
          <MaxFileSize>100MB</MaxFileSize>
        </triggeringPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
          <pattern>%date [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
      </appender>
      <!--<logger name="bndtools.m2e.MavenWorkspaceRepository" level="DEBUG" />-->
      <root level="ERROR">
        <appender-ref ref="FILE" />
        <appender-ref ref="STDOUT" />
      </root>
    </configuration>
  • notice the FILE appender FileNamePattern references an existing system property which is unique for each workspace. This means a generated log file will be contained in each workspace (as configured it will be at ${workspace_loc}/.metadata/.log-%i-back.log)

A few points

  • the configuration file is scanned every 30 seconds by logback engine and so Eclipse restart is not required
  • add logger to adjust any specific logging categories as needed
Clone this wiki locally