Passing logger level via parameter or determining programmatically?

Hi all, Is there any way to accomplish setting a log level (error, warn, ...) via a parameter, so that I do not have to explicitly code logger.error(...), logger.warn(...)? I would like to be able to code something like logger.log("foo={}", foo); and have it determine the level based on a previously set value. If I could do something like this, then I could change the logging level dynamically in specific classes, rather than changing the level for an entire class as I've seen discussed in the past. Thanks, Larry Smith

There isn't anything native to SLF4J, but it's relatively trivial to implement using the decorator pattern. I've got a library here: http://GitHub.com/Mahoney/slf4j-utils - which does just this, and which I'm planning on releasing to Maven central pretty soon. On 5 Oct 2012, at 17:29, "Smith, Larry (ECS - Enterprise Cloud Service)" <larry.smith5@hp.com> wrote:
Hi all,
Is there any way to accomplish setting a log level (error, warn, ...) via a parameter, so that I do not have to explicitly code logger.error(...), logger.warn(...)?
I would like to be able to code something like logger.log("foo={}", foo); and have it determine the level based on a previously set value.
If I could do something like this, then I could change the logging level dynamically in specific classes, rather than changing the level for an entire class as I've seen discussed in the past.
Thanks, Larry Smith _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user

Hi Robert, Took a quick look at the library. It's very close to what I was looking for. Larry Smith -----Original Message----- From: logback-user-bounces@qos.ch [mailto:logback-user-bounces@qos.ch] On Behalf Of Robert Elliot Sent: Friday, October 05, 2012 11:21 AM To: logback users list Subject: Re: [logback-user] Passing logger level via parameter or determining programmatically? There isn't anything native to SLF4J, but it's relatively trivial to implement using the decorator pattern. I've got a library here: http://GitHub.com/Mahoney/slf4j-utils - which does just this, and which I'm planning on releasing to Maven central pretty soon. On 5 Oct 2012, at 17:29, "Smith, Larry (ECS - Enterprise Cloud Service)" <larry.smith5@hp.com> wrote:
Hi all,
Is there any way to accomplish setting a log level (error, warn, ...) via a parameter, so that I do not have to explicitly code logger.error(...), logger.warn(...)?
I would like to be able to code something like logger.log("foo={}", foo); and have it determine the level based on a previously set value.
If I could do something like this, then I could change the logging level dynamically in specific classes, rather than changing the level for an entire class as I've seen discussed in the past.
Thanks, Larry Smith _______________________________________________ Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
Logback-user mailing list Logback-user@qos.ch http://mailman.qos.ch/mailman/listinfo/logback-user
participants (2)
-
Robert Elliot
-
Smith, Larry (ECS - Enterprise Cloud Service)