Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a contextListener in logback groovy configuration?

Tags:

logback

I want to use LevelChangePropagator as logback contextListener, as described in the logback manual. However in my project logback is configured using groovy, and there's nothing in the official documentation about configuring contextListener in groovy. Logback provides a tool to translate xml configuration into a groovy configuration. I tried it, but it just skipped the contextListener part.

I've found exactly one answer to my question in the logback mailing lists, but solution doesn't seem to be working for me.

EDIT:
I've created an issue in logback JIRA about missing documentation: http://jira.qos.ch/browse/LOGBACK-979. Still, maybe someone knows the answer?

like image 490
Grzegorz Olszewski Avatar asked Apr 24 '14 08:04

Grzegorz Olszewski


People also ask

How do I change the Logback configuration file?

Setting the location of the configuration file via a system property. You may specify the location of the default configuration file with a system property named "logback. configurationFile" . The value of this property can be a URL, a resource on the class path or a path to a file external to the application.

How do I enable debug logs in Logback?

debug=true to enable debugging of the logback setup. Unfortunately, there is no way to enable debugging via a System property. You have to use <configuration debug="true"> in the logback. xml .

What is context name in Logback XML?

Setting the context name is a simple and straightforward method in order to distinguish between multiple applications logging to the same target. This last example illustrates naming of the logger context. Adding the contextName conversion word in layout's pattern will output the said name.


1 Answers

Add this to logback.groovy:

import ch.qos.logback.classic.jul.LevelChangePropagator

def lcp = new LevelChangePropagator()
lcp.context = context
lcp.resetJUL = true
context.addListener(lcp)
like image 189
Don Bottstein Avatar answered Oct 12 '22 12:10

Don Bottstein