logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter DePasquale <peter.depasqu...@gmail.com>
Subject Re: Simple test case for logging uner a tomcat web app
Date Thu, 25 Apr 2013 11:54:29 GMT
Remko,

Thanks for clarifying. One of the reasons that I asked, was that I was
thinking of incorporating a section of logging in a Java program with some
of my introductory course materials. Here, we go about a semester and a
half before we introduce packaging. Thus, the occurrence of default
packaged code.


On Thu, Apr 25, 2013 at 1:05 AM, Remko Popma <remkop@yahoo.com> wrote:

> Peter,
>
> Glad to be of help.
>
> First, you NEED a root logger. I finished analysis of the bug and other
> loggers are ignored if no root element exists.
> Not sure yet if we'll fix the code or the docs, but that is the behavior
> of beta5.
>
> The default (nameless) package doesn't play well with logger names.
> You'd need to specify the class name as the logger name. Wildcarts like
> "*" won't work. "" didn't work for me. Better use the root logger.
> (In your own code I'd strongly recommend using packages for anything that
> isn't throw-away code. )
>
> Hope this helps,
> Remko
>
> Sent from my iPhone
>
> On 2013/04/25, at 11:59, Peter DePasquale <peter.depasquale@gmail.com>
> wrote:
>
> > Thanks Remko, you have validated my sanity.
> >
> > I was finally able to sit down tonight and integrate in your suggestions
> > and all works well. I'm also thrilled to have found a bug! Now I can
> return
> > to successful logging in my application and track down a bunch of other
> > problems on my end.
> >
> > I'm sure I will have additional questions... oh here's one...
> >
> > As a college instructor of Java we often don't teach packaging in the
> first
> > semester, so I see a lot of code that is not packaged.
> >
> > As I was fiddling with my test case, I attempted (earlier) to use
> > unpackaged code and to make a named logger to catch the trace messages.
> I'm
> > guessing that I should really use a root logger for this, but are named
> > loggers able to support unpackaged code?
> >
> > That is, can I do this?
> >
> > <loggers>
> >  <logger name="*" level="trace">
> >    <appender-ref ref="foo"/>
> >  </logger>
> > </loggers>
> >
> > Or, should one use: name=""?  I think I actually got this to work once,
> but
> > it was not clear if this is a valid approach. Again, I'm guessing the
> root
> > logger is the way to go here.
> >
> > Thanks again for the help!
> >
> >
> >
> > On Wed, Apr 24, 2013 at 1:39 AM, Remko Popma <remkop@yahoo.com> wrote:
> >
> >> Peter,
> >>
> >> I don't have Tomcat installed but I was able to reproduce the problem
> in a
> >> standalone test using your configuration.
> >>
> >> There is a couple of things I found.
> >> First, File appenders have these configuration settings by default:
> >> bufferedIO="true" and immediateFlush="false".
> >>
> >> This means that messages will not be written to disk until the buffer is
> >> full.
> >> I think we should improved the documentation for this and I've filed
> this
> >> JIRA ticket:
> >> https://issues.apache.org/jira/browse/LOG4J2-218
> >>
> >>
> >> Second, looks like you found a bug!
> >> Even after adding immediateFlush="true" to the File config, the
> >> trace-log.txt file is empty.
> >>
> >> I don't understand the underlying cause yet, but if the config has a
> named
> >> logger
> >> and no root logger, the named logger internally ends up with no Appender
> >> objects.
> >> I've filed another JIRA for this:
> >> https://issues.apache.org/jira/browse/LOG4J2-219
> >>
> >>
> >> Workaround:
> >> 1. Specify immediateFlush="true" in the File appender config
> >> 2. Replace the named logger with a root logger configuration
> >>
> >> The config below worked for me.
> >> (In my standalone test, that is. I haven't installed Tomcat.
> >> Can you try this and let me know if there is any problem?)
> >>
> >> <?xml version="1.0" encoding="UTF-8"?>
> >> <configuration status="warn">
> >>        <appenders>
> >>                <File name="tracelog"
> >> fileName="${sys:catalina.base}/logs/trace-log.txt"
> >>                                immediateFlush="true" append="false">
> >>                        <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t]
> >> %-5level %logger{36} - %msg%n"/>
> >>                </File>
> >>        </appenders>
> >>
> >>        <loggers>
> >>                <root level="trace">
> >>                        <appender-ref ref="tracelog"/>
> >>                </root>
> >>        </loggers>
> >> </configuration>
> >>
> >> Sent from my iPhone
> >>
> >> On 2013/04/24, at 10:13, Peter DePasquale <peter.depasquale@gmail.com>
> >> wrote:
> >>
> >>> I continue to struggle achieving basic logging results under my web app
> >>> under tomcat. It seemed to work months ago, but when I upgraded to the
> >>> latest beta logging failed.
> >>>
> >>> I returned to examine my config and failed to solve the problem. I
> >> emailed
> >>> this list about this and I received no response. After asking for help
> a
> >>> second time Ralph suggested I post code.
> >>>
> >>> Thus, I have attempted to simplify my problem down and post a VERY
> SIMPLE
> >>> web app that attempts to do trace and error logging.  I was trying to
> get
> >>> this into to separate files, but I'm learning that that's apparently
> not
> >>> really the model I should embrace as a logging novice.
> >>>
> >>> Now I have trace logging going to one file. However, despite the app
> >>> running successfully, an empty log file is created.  I can't determine
> >> what
> >>> I'm doing wrong and seek help one last time on my inability to grasp
> the
> >>> correct form for logging of this nature.
> >>>
> >>> I really don't want to go back to println statements, but if I can't
> make
> >>> this work, I will. My application is my academic research project and
> I'm
> >>> delayed in developing new features because I got mired down in trying
> to
> >>> solve these issues so that I can support logging in my app (seemed
> smart
> >> at
> >>> the time).
> >>>
> >>> Regardless, the code is posted here at github. I welcome any help that
> >>> anyone can provide by download or visual inspection. I am posting this
> >> and
> >>> setting away for the night as I can not work on this today any longer.
> >>>
> >>> My setup is a Mac OSX 10.6 running Tomcat 7.0.37 locally. Beyond the
> >> basic
> >>> apps that Tomcat is preloaded with, this is the only running app.
> >>>
> >>> https://github.com/depasqua/log4j2tester
> >>>
> >>> Thanks. Sorry for my vent.
> >>> --
> >>> Peter J. DePasquale, Ph.D.
> >>> Department of Computer Science
> >>> The College of New Jersey
> >>> (e) depasqua [at] tcnj [dot] edu
> >>> (p) 609-771-2806
> >>> (f) 609-637-5190
> >>> (o) Holman Hall - Room 238
> >>> (l) Holman Hall - Room 255
> >
> >
> >
> > --
> > Peter J. DePasquale, Ph.D.
> > Department of Computer Science
> > The College of New Jersey
> > (e) depasqua [at] tcnj [dot] edu
> > (p) 609-771-2806
> > (f) 609-637-5190
> > (o) Holman Hall - Room 238
> > (l) Holman Hall - Room 255
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Peter J. DePasquale, Ph.D.
Department of Computer Science
The College of New Jersey
(e) depasqua [at] tcnj [dot] edu
(p) 609-771-2806
(f) 609-637-5190
(o) Holman Hall - Room 238
(l) Holman Hall - Room 255

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message