[logback-user] Retrieving the log filenames
Ceki Gulcu
ceki at qos.ch
Tue Mar 29 14:32:51 CEST 2011
Hello Clemens,
Lance's suggestion is almost certaint on target. Do check your classpath
to see if there are multiple instances of logback-classic lying around.
--
Ceki
On 29.03.2011 14:13, Clemens Siebler wrote:
> Thanks for the hint Lance! I feel like this could be the issue. However,
> I haven't managed to actually find a solution to it. I tried starting my
> application with -verbose:class, but I can only see one entry of:
> [Loaded ch.qos.logback.classic.LoggerContext from
> file:/yyy/logback-classic-0.9.21.jar]. I suppose there should be
> multiple of these, if that actually is the problem? Thanks for your help!
>
>
> On Fri, Mar 25, 2011 at 4:54 PM, Lance White <lance.white at logicscope.com
> <mailto:lance.white at logicscope.com>> wrote:
>
> >> However, when I try to use this code outside of my test
> environement, I get the following Exception on the first line:
> >> java.lang.ClassCastException:
> ch.qos.logback.classic.LoggerContext cannot be cast to
> ch.qos.logback.classic.LoggerContext
>
> This is usually a multiple classloader problem.
>
> Lance
>
> *From:*logback-user-bounces at qos.ch
> <mailto:logback-user-bounces at qos.ch>
> [mailto:logback-user-bounces at qos.ch
> <mailto:logback-user-bounces at qos.ch>] *On Behalf Of *Clemens Siebler
> *Sent:* 24 March 2011 16:16
> *To:* logback users list
> *Subject:* Re: [logback-user] Retrieving the log filenames
>
> Ok, I figured out how to get at least the base logfile:
> LoggerContext ctx = (LoggerContext)
> LoggerFactory.getILoggerFactory();
> for (Logger l : ctx.getLoggerList()) {
> ch.qos.logback.classic.Logger log =
> (ch.qos.logback.classic.Logger) l;
> Iterator<Appender<ILoggingEvent>> it =
> log.iteratorForAppenders();
> while (it.hasNext()) {
> Appender<ILoggingEvent> ap = it.next();
> if (ap instanceof FileAppender<?> || ap instanceof
> RollingFileAppender<?>) {
> FileAppender<?> fileAppender = (FileAppender<?>)ap;
> System.out.println(fileAppender.getFile());
> }
> }
> }
>
> However, when I try to use this code outside of my test
> environement, I get the following Exception on the first line:
> java.lang.ClassCastException: ch.qos.logback.classic.LoggerContext
> cannot be cast to ch.qos.logback.classic.LoggerContext
>
> Any ideas? I'm currently using Jetty, slf4j and logback. However, it
> seems that there are still some dependencies on log4j in Jetty that
> I can't get rid of...
>
> On Tue, Mar 22, 2011 at 10:23 AM, Clemens Siebler
> <clemens.siebler at googlemail.com
> <mailto:clemens.siebler at googlemail.com>> wrote:
>
> As far as log4j goes, the getAppender function can be used. However,
> I have not managed to get this one working for logback. Any ideas?
>
> On Mon, Mar 21, 2011 at 3:42 PM, Clemens Siebler
> <clemens.siebler at googlemail.com
> <mailto:clemens.siebler at googlemail.com>> wrote:
>
> Let's assume the user only changes the logging levels/filter during
> runtime, nothing else.
>
> On Mon, Mar 21, 2011 at 3:32 PM, David Roussel
> <nabble at diroussel.xsmail.com <mailto:nabble at diroussel.xsmail.com>>
> wrote:
>
> Would a change notifier be told of the new filename? I'm not sure,
> but it's worth a check.
>
>
> On 21 Mar 2011, at 13:56, Clemens Siebler
> <clemens.siebler at googlemail.com
> <mailto:clemens.siebler at googlemail.com>> wrote:
>
> > Hi all,
> >
> > I'm currently using Logback (SLF4J) with a TimeBasedRollingPolicy
> defined in logback.xml. Everything works fine, however, I'd like to
> retrieve the filenames of the current logging session since the
> application started. The user can obviously change the log filenames
> and policies in logback.xml, so I don't want them hardcoded in the
> source. My goal is to retrieve these filenames straight within Java
> in order to do some more processing with them. Is there any
> possibility in logback/slf4j to retrieve those names?
> >
> > I currently aquire the logger via:
> > Logger logger = LoggerFactory.getLogger(Test.class);
> >
> > but obviously, this Logger object in particular doesn't provide
> such functionality. Any ideas?
> >
> > Thanks in advance,
> > Clemens
More information about the Logback-user
mailing list