Official "Holler!" concerning my topic on stackoverflow.com

Hi Ceki, I'm referring to your comment on http://stackoverflow.com/questions/945659/is-there-any-way-to-automatically-... I've never configured Logback programatically and always assumed that Joran was "the way" to do it. How can this be done? I have to admit that I haven't reread the manual concerning this topic, yet, but thought I'd ask you anyway since it's probably quite easy for you. Would you like to integrate the code into a new logback-module (a new module so the compile dependency to JUnit doesn't pollute anything else)? After I've enhanced and documented it, obviously... I was looking for something like that for more than 4 years so I'm quite happy that I have found such a solution... others would probably benefit, too. Regards + thanks, Joern.

Hi Joern, To set the level of a logger: import ch.qos.logback.classic.Logger; LoggerContext loggerContext = (LoggerContext) loggerFactory; Logger logger = (Logger) loggerContext.getLogger("a.name"); Level oldLevel = logger.getLevel(); logger.setLevel(Level.a_level_of_your choice); To create an appender, there are a bunch of examples under http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/package-summary.... see for example http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/RenamingTest.htm... Once you create an appender, you can easily associate it with a logger logger.addAppender(appender); You can later remove it by invoking logger.detachAppender(appender) // detach by appender reference or logger.detachAppender("appender name"); // detach by name Let me know if you have further questions. HTH, Joern Huxhorn wrote:
Hi Ceki,
I'm referring to your comment on http://stackoverflow.com/questions/945659/is-there-any-way-to-automatically-...
I've never configured Logback programatically and always assumed that Joran was "the way" to do it. How can this be done? I have to admit that I haven't reread the manual concerning this topic, yet, but thought I'd ask you anyway since it's probably quite easy for you.
Would you like to integrate the code into a new logback-module (a new module so the compile dependency to JUnit doesn't pollute anything else)? After I've enhanced and documented it, obviously... I was looking for something like that for more than 4 years so I'm quite happy that I have found such a solution... others would probably benefit, too.
Regards + thanks, Joern.
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

On 08.06.2009, at 20:47, Ceki Gulcu wrote:
Hi Joern,
To set the level of a logger:
import ch.qos.logback.classic.Logger;
LoggerContext loggerContext = (LoggerContext) loggerFactory; Logger logger = (Logger) loggerContext.getLogger("a.name"); Level oldLevel = logger.getLevel(); logger.setLevel(Level.a_level_of_your choice);
To create an appender, there are a bunch of examples under http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/package-summary.... see for example http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/RenamingTest.htm...
Once you create an appender, you can easily associate it with a logger
logger.addAppender(appender);
You can later remove it by invoking
logger.detachAppender(appender) // detach by appender reference or logger.detachAppender("appender name"); // detach by name
Let me know if you have further questions. HTH,
Hi Ceki, I tried to implement the test-base like this but nothing was written to the logfile. The files are created but they have a size of 0 bytes. Please have a look at http://apps.sourceforge.net/trac/sulky/browser/trunk/sulky-junit/src/main/ja... My futile attempt is commented out. I'm sure I miss something really stupid :p Beside that, is there some easier way to just restart the usual logging configuration process instead of manually doing it like I do in resetLogging? Thanks, Jörn.

Hello Joern, It looks like you are not setting the context for the PatternLayout. To see what is going on, you should invoke StatusPrinter. It will tell you what you are missing. Joern Huxhorn wrote:
On 08.06.2009, at 20:47, Ceki Gulcu wrote:
Hi Joern,
To set the level of a logger:
import ch.qos.logback.classic.Logger;
LoggerContext loggerContext = (LoggerContext) loggerFactory; Logger logger = (Logger) loggerContext.getLogger("a.name"); Level oldLevel = logger.getLevel(); logger.setLevel(Level.a_level_of_your choice);
To create an appender, there are a bunch of examples under http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/package-summary....
see for example http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/RenamingTest.htm...
Once you create an appender, you can easily associate it with a logger
logger.addAppender(appender);
You can later remove it by invoking
logger.detachAppender(appender) // detach by appender reference or logger.detachAppender("appender name"); // detach by name
Let me know if you have further questions. HTH,
Hi Ceki, I tried to implement the test-base like this but nothing was written to the logfile. The files are created but they have a size of 0 bytes.
Please have a look at http://apps.sourceforge.net/trac/sulky/browser/trunk/sulky-junit/src/main/ja...
My futile attempt is commented out. I'm sure I miss something really stupid :p
Beside that, is there some easier way to just restart the usual logging configuration process instead of manually doing it like I do in resetLogging?
Thanks, Jörn. _______________________________________________ logback-dev mailing list logback-dev@qos.ch http://qos.ch/mailman/listinfo/logback-dev
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch

I've set the context, now. Only 15:17:48,284 |-INFO in ch.qos.logback.core.FileAppender[FILE] - File property is set to [/tmp/logging17790log] is printed. Nothing about attaching this to that or "root level set to ALL". Strange. On 09.06.2009, at 14:59, Ceki Gulcu wrote:
Hello Joern,
It looks like you are not setting the context for the PatternLayout. To see what is going on, you should invoke StatusPrinter. It will tell you what you are missing.
Joern Huxhorn wrote:
On 08.06.2009, at 20:47, Ceki Gulcu wrote:
Hi Joern,
To set the level of a logger:
import ch.qos.logback.classic.Logger;
LoggerContext loggerContext = (LoggerContext) loggerFactory; Logger logger = (Logger) loggerContext.getLogger("a.name"); Level oldLevel = logger.getLevel(); logger.setLevel(Level.a_level_of_your choice);
To create an appender, there are a bunch of examples under http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/package-summary.... see for example http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/RenamingTest.htm...
Once you create an appender, you can easily associate it with a logger
logger.addAppender(appender);
You can later remove it by invoking
logger.detachAppender(appender) // detach by appender reference or logger.detachAppender("appender name"); // detach by name
Let me know if you have further questions. HTH,
Hi Ceki, I tried to implement the test-base like this but nothing was written to the logfile. The files are created but they have a size of 0 bytes. Please have a look at http://apps.sourceforge.net/trac/sulky/browser/trunk/sulky-junit/src/main/ja... My futile attempt is commented out. I'm sure I miss something really stupid :p Beside that, is there some easier way to just restart the usual logging configuration process instead of manually doing it like I do in resetLogging? Thanks, Jörn. _______________________________________________ logback-dev mailing list logback-dev@qos.ch http://qos.ch/mailman/listinfo/logback-dev
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ logback-dev mailing list logback-dev@qos.ch http://qos.ch/mailman/listinfo/logback-dev

In principle, status messages are emitted by components other than Joran only when things go wrong. Setting the level of a logger is too low level an opetation to warrant a status message. However, Joran, which is higher level, does emit a status message when its sets the level of a logger. Joern Huxhorn wrote:
I've set the context, now.
Only 15:17:48,284 |-INFO in ch.qos.logback.core.FileAppender[FILE] - File property is set to [/tmp/logging17790log] is printed. Nothing about attaching this to that or "root level set to ALL". Strange.
On 09.06.2009, at 14:59, Ceki Gulcu wrote:
Hello Joern,
It looks like you are not setting the context for the PatternLayout. To see what is going on, you should invoke StatusPrinter. It will tell you what you are missing.
Joern Huxhorn wrote:
On 08.06.2009, at 20:47, Ceki Gulcu wrote:
Hi Joern,
To set the level of a logger:
import ch.qos.logback.classic.Logger;
LoggerContext loggerContext = (LoggerContext) loggerFactory; Logger logger = (Logger) loggerContext.getLogger("a.name"); Level oldLevel = logger.getLevel(); logger.setLevel(Level.a_level_of_your choice);
To create an appender, there are a bunch of examples under http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/package-summary....
see for example http://logback.qos.ch/xref-test/ch/qos/logback/core/rolling/RenamingTest.htm...
Once you create an appender, you can easily associate it with a logger
logger.addAppender(appender);
You can later remove it by invoking
logger.detachAppender(appender) // detach by appender reference or logger.detachAppender("appender name"); // detach by name
Let me know if you have further questions. HTH,
Hi Ceki, I tried to implement the test-base like this but nothing was written to the logfile. The files are created but they have a size of 0 bytes. Please have a look at http://apps.sourceforge.net/trac/sulky/browser/trunk/sulky-junit/src/main/ja... My futile attempt is commented out. I'm sure I miss something really stupid :p Beside that, is there some easier way to just restart the usual logging configuration process instead of manually doing it like I do in resetLogging? Thanks, Jörn. _______________________________________________ logback-dev mailing list logback-dev@qos.ch http://qos.ch/mailman/listinfo/logback-dev
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch _______________________________________________ logback-dev mailing list logback-dev@qos.ch http://qos.ch/mailman/listinfo/logback-dev
_______________________________________________ logback-dev mailing list logback-dev@qos.ch http://qos.ch/mailman/listinfo/logback-dev
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch
participants (2)
-
Ceki Gulcu
-
Joern Huxhorn