Eric B. wrote: > Hi, > > I'm trying to get Tomcat to log the output each context individually in its > own log file. > > I tried using the swallowOutput in my <context> object definition, but am > getting some really weird results from it. My webapp uses log4j to do its > logging with its own log4j.xml file within the webapp, and all log4j's > output is > defined as using the org.apache.log4j.ConsoleAppender. > > My context.xml file is: > conf/Catalina/localhost/ROOT.xml: > <Context debug="0" reloadable="true" distributable="true" > swallowOutput="true"> > > <ResourceLink name="jdbc/dame" > global="jdbc/eppe" > type="javax.sql.DataSource" /> > > <ResourceLink name="mail/dame" > global="mail/dame" > type="javax.mail.Session" /> > > </Context> > > > ${catalina.base}/conf/logging.properties: > handlers = 1catalina.org.apache.juli.FileHandler, > 2localhost.org.apache.juli.FileHandler, > 3manager.org.apache.juli.FileHandler, > 4admin.org.apach\e.juli.FileHandler, > 5host-manager.org.apache.juli.FileHandler, > 6root.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler > > 6root.org.apache.juli.FileHandler.level = ALL > 6root.org.apache.juli.FileHandler.directory = ${catalina.base}/logs > 6root.org.apache.juli.FileHandler.prefix = root. > > org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/].level = > ALL > org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/].handlers = > 6root.org.apache.juli.FileHandler > > > > Based on that configuration (and swallowOutput documentation) I would expect > that all logging from my root context would therefor go through > 6root.org.apache.juli.FileHandler log file. However, I seem to only be > getting some logging captured in the root.log logfile. > > It is extremely confusing; there doesn't seem to be any pattern. Some > webapp logs go to root.log, other still are displayed on stdout, and > therefore in catalina.out. Like I said, all log msgs in the webapp use the > same log4j ConsoleAppender. > > I'm running Tomcat 6.0.18. I searched through the changelog for 6.0.19 and > 6.0.20 and don't see anything that relates to this, so I am wondering if > this is an issue that still exists. > > Is my configuration wrong?
Yes, no, sort of... You need to keep in mind the way swallowOutput and log4j are intended to work. swallowOutput is intended to capture direct usage of stdout and stderr by a web application. When Tomcat starts, it replaces System.out and System.err with custom PrintStreams. These custom PrintStreams use ThreadLocals (set when request processing starts, and cleared when request processing ends) to capture anything the thread writes to stdout or stderr. The captured output is then directed to the appropriate logger. If no thread local is set the data is passed through to stdout/stderr as appropriate. swallowOutput is not intended to capture the output of a logging framework. When a log message is written to JULI, log4j or just about any logging framework there is usually an element of buffering. Typically there is a single console appender (names vary between frameworks) that all log messages are passed to which are then written out as the buffer fills. The thread that does the actual write is probably not the thread the generated most of the output. It is quite likely that this write will happen outside of the request processing chain and hence won't be caught by the swallowOutput code. Even if it were captured, the chances are the data won't be where you want it. To put this another way, the intended usage of swallowOutput is: webapp -> stdout -> swallowOutput -> file You are trying to do webapp -> logging framework -> stdout -> swallowOutput -> file swallowOutput was never intended to support what you are trying to achieve. Depending on how data is buffered you may get the results you want, apparently mixed up log messages or no log messages at all. I think you are trying to combine Tomcat's logging and your application's logging in a single file for each web application. That should be possible without using swallowOutput providing the app and Tomcat use the same logging framework. In this case you shoudl be able to configure things such that everythign for an app gets written to a single file. Further, if your app does write to stdout then swallowOutput can be used to redirect it to a logger. I should add I haven't tested this so YMMV. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org