Currently on our project we are seeing some DEBUG statements printed on our tomcat logs such as this:
12:09:00.824 [localhost-startStop-1] DEBUG n.j.w.r.h.b.AbstractResourceBundleHandler - Storing a generated bundle with an id of:/script/lib/itegration.dataTables.bootstrap.js 12:09:00.850 [localhost-startStop-1] DEBUG n.j.w.r.h.b.AbstractResourceBundleHandler - Storing a generated bundle with an id of:/script/lib/itegration.dataTables.bootstrap.js
We have determined that the debug statements that are being logged are caused because the condition LOGGER.isDebugEnabled() in the JAWR AbstractResourceBundleHandler.java class is always true. The snip of the code that logs is as follows:
if (LOGGER.isDebugEnabled()) {
String msg = "Storing a generated "
+ (gzipFile ? "and gzipped" : "")
+ " bundle with an id of:" + bundleName;
LOGGER.debug(msg);
}
As you can see there is a LOGGER.isDebugEnabled() which is always true. Is there a way to configure the logging level for this package/class/jar? We are currently using log4j as our logging framework and have tried configuring this package to log only INFO level but that has not worked. We also have the jawr.debug.on property set to false (jawr.debug.on=false)
I understand that JAWR is using slf4j for their logger and there is a way to use the slf4j bridge to log4j which we have configured, we just cannot get the logging level configuation for this package to work.
Does anyone know a way to set the LOGGER.isDebugEnabled() set to false so that these DEBUG log statements do not appear in our tomcat logs?
We are using log4j.xml not a properties file and would like to keep using the .xml configuration if possible.
Thank you
Adding this to our log4j.xml configuration file
<category name="net.jawr">
<priority value="INFO" />
</category>
works fine.
Related
We are using log4net for our application logging in azure.
We configured it according to this document , the logs are stored in
d:/home/LogFiles/Application/Log4netfile-[%processid].txt
we can download the files from https://xxxx.scm.azurewebsites.net/api/dump and I can also see them in Log stream, there it looks like this
2022-02-06T18:22:57 PID[29616] Verbose log4net: Adding appender named [FileAppender] to logger [root].
2022-02-06T18:22:57 PID[29616] Verbose log4net: Hierarchy Threshold []
2022-02-06T18:22:58 PID[29616] Verbose LOG4NET Fatal LOG4NET LOG4NET
2022-02-06T18:22:58 PID[29616] Verbose LOG4NET Debug Message Message
Line items like:
log4net: Adding appender named
are created by log4net during internal setup (using debug=true), and those show up in our AppServiceAppLogs, however, items which are genereted by the logger using:
Logger.Fatal("LOG4NET Fatal LOG4NET LOG4NET");
are visible in stream and files but they are not showing up in AppServiceLogs.
I tried multiple different appenders the only one which shows up in Log-Streams and in files is FileAppender (or RollingFileAppender), all others are not showing in LogStreams or (as expected) in the files.
Based on this https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs#send-logs-to-azure-monitor I assume that everything writen to the files should be than sent to azure-monitor - but in our case this is not hapening. Could you provide some reference about implementation / code how the sending of the files is done, and which process does that ?
I am wandering is there anything which we could configure differently to get the log-items to end up in AppServiceLogs? Or should we use some other appender?
I am aware of the issue in AspNetTraceAppender and I am trying to avoid implementation of new appender.
There are a few things you can look into:
Call log4net configure before writing to your log file (only once is enough):
log4net.Config.XmlConfigurator();
or
log4net.Config.XmlConfigurator.Configure();
and then you can add flushing to your configuration:
<appender name="AzureTraceAppender" type="log4net.Appender.TraceAppender">
<param name="ImmediateFlush" value="true" />
<layout type="log4net.Layout.PatternLayout">
<!-- can be any pattern you like -->
<conversionPattern value="%logger - %message" />
</layout>
</appender>
Immediately, this will flush the message.
In Global.asax, To make log4net read your configuration.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// Initialize log4net.
log4net.Config.XmlConfigurator.Configure();
}
Make sure Azure Diagnostics has configured to all information needed for debugging.
After that, you can enable internal log4net debugging. Refer internal debugging on this log4net faq page. Standard it should log to your listener you have configured. To the trace element Add the autoflush="true" option . Or find directory on the worker role you can write to and access to read your logs.
I am testing openshift based simple jsf app with Jbossas server.
But it seems that wrong encoding comes in logs by some reason...
For example, some code from jsf bean method:
System.out.println("перед dao.addTask");
System.out.println("name = " + name); // where name value is "экстраординарно"
In server logs we have:
□□□□□□□□□□ dao.addTask
name = □□□□□□□□□□□□□□□
What is the reason for wrong encoding in logs when java code uses utf-8 encoding ?
I think you have to update logger encoding in standalone.xml file. Every OpenShift application has .openshift directory that contains few configuration files and other OpenShift specific files. For JBoss application, there is standalone.xml inside .openshift/config directory. Update following in standalone.xml
<periodic-rotating-file-handler name="FILE">
to
<periodic-rotating-file-handler name="FILE" encoding="UTF-8">
Hope this will help you.
I am into the development of a core dll where I have a class library.I want to use log4net to enable logging for exceptions. I have an app.config file in the class library where i have given the settings for the log4net.However when I test the class library the log4net does'nt create logs until i add the app.config in the calling project inspite of the fact that i had added [assembly: log4net.Config.XmlConfigurator(Watch = true)] in the class libary's assemblyinfo.cs and I am using log4net.ILog logger = log4net.LogManager.GetLogger(typeof(ErrorHandler)) where ErrorHandler is the name of my class library's class where log4net's calling functions are handled.Any ideas on what is going wrong?
Secondly, what I want to acheive is the users of my dll will just pass the location where they want to create logs and whether they want to create logs in event viewer or log files from their app.config? They will not handle any other setting of log4net.
Any suggestions or code snippets for the first issue and the second problem?
Only the "main" app.config is active for a .Net application. Your library config file is simply ignored. Either you transfer your settings to the main config file or you use an external config file for log4net. You configure it then for instance like this (assuming you call it log4net.config):
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
Please note that the structure of the config file is a bit different:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="YourAppender" type="..." >
....
</appender>
<root>
<level value="ALL" />
<appender-ref ref="YourAppender" />
</root>
</log4net>
As for your second problem: I am not sure how flexible this has to be. Is it just switching from file appender to event log appender? Depending on your answer you may consider two prepare to configuration files (e.g. file.log4net and eventlog.log4net) and read the configuration as needed (in that case you cannot use the attribute: you call the Configure() method directly) or if your requirements are more complex you might even end up configuring log4net programatically.
I'm having a project using JSF2 (2.1.2), Richfaces4 (4.0.0.Final) on tomcat6 (6.0.28). In order to manage portability between Tomcat and WebSphere7 for my EARs, I have the following jars inside my tomcat lib: el-api-2.2.jar, jsf-api-2.1.2.jar, jsf-impl-2.1.2.jar, validation-api-1.0.0.GA.jar.
My problem is that I never managed to change the log levels of JSF or Richfaces and except from the initialization ones, I don't see any inside my console. Even when I get exceptions in my server response !
I tried several ways:
1) Inside my applications, I'm using slf4j and log4j. So the natural way would be to use SLF4JBridgeHandler.install(). I made a small servlet to call this method during its init() method and added a 'load-on-startup' to be sure it's loaded before JSF Servlet (I'm not sure tomcat cares at all about this load-on-startup directive because I still get logs from JSF init before), e.g.:
INFO: JSF1027 : [null] Les objets ELResolvers de JSF n’ont pas été enregistrés avec le conteneur JSP.
09-09-2011 16:50:58:591 [Thread-2] 937 DEBUG com.jsf.test.SLF4JBridgeHandlerInstallerServlet - SLF4JBridgeHandler.install() OK!
I also added some configuration in my log4j.xml:
<logger name="javax.faces"><level value="debug"/></logger>
<logger name="com.sun.faces"><level value="debug"/></logger>
<logger name="javax.enterprise.resource.webcontainer.jsf"><level value="debug"/></logger>
But I don't see any logs in my console when displaying a JSF page...
I also tried using a filter to call SLF4JBridgeHandler.install() before the execution of the JSF Servlet, but I only get a lot of OK logs from my filter...
2) I tried to follow the tutorial here exactly (it creates new files in tomcat log folder for each logger of JSF2). I tried by changing the logging.properties inside the conf folder of tomcat and by adding a new logging.properties inside my src/resources/ folder in my application. But no luck...
3) I tried to add the JSF loggers to the the logging.properties inside my tomcat by adding this:
javax.enterprise.resource.webcontainer.jsf.managedbean.level=FINEST
javax.enterprise.resource.webcontainer.jsf.managedbean.handlers = java.util.logging.ConsoleHandler
javax.enterprise.resource.webcontainer.jsf.config.level=FINEST
javax.enterprise.resource.webcontainer.jsf.config.handlers = java.util.logging.ConsoleHandler
javax.enterprise.resource.webcontainer.jsf.facelets.level=FINEST
javax.enterprise.resource.webcontainer.jsf.facelets.handlers = java.util.logging.ConsoleHandler
javax.enterprise.resource.webcontainer.jsf.resource.level=FINEST
javax.enterprise.resource.webcontainer.jsf.resource.handlers = java.util.logging.ConsoleHandler
javax.enterprise.resource.webcontainer.jsf.lifecycle.level=FINEST
javax.enterprise.resource.webcontainer.jsf.lifecycle.handlers = java.util.logging.ConsoleHandler
No luck yet...
4) I tried to use log4j inside tomcat instead of juli by following this documentation. It seems to work well, but changing the resulting log4j.properties to put the JSF loggers in DEBUG didn't work...
Any idea ?
Regards,
Florian
Two facts:
JSF uses java.util.logging API which is to be configured by a logging.properties file in the root of the runtime classpath.
The logging.properties file of the currently(!) running runtime environment (JRE) will be used.
If you're running Tomcat from inside an IDE like Eclipse, then Tomcat's own logging.properties won't be used. The one in JDK/JRE/lib will be used where "JDK" is the JDK install folder such as jdk1.6.0_23. If you'd like to explicitly specify the location of the logging.properties file, then you would need to set a VM argument:
-Djava.util.logging.config.file=/path/to/tomcat/logging.properties
Regardless of the logging file used, in order to enable Mojarra logging, you need to open the logging.properties template file in question, scroll to the bottom and edit the following line near the bottom
java.util.logging.ConsoleHandler.level = INFO
into
java.util.logging.ConsoleHandler.level = ALL
so that the global console level is set to ALL instead of INFO. Otherwise lower levels than INFO just won't be logged at all.
Finally add the following two lines to the very bottom of the file
javax.faces.level = ALL
com.sun.faces.level = ALL
javax.enterprise.resource.webcontainer.jsf.level = ALL
The first turns on all JSF API logging, the second turns on all JSF impl (Mojarra) logging, and the third turns on all JSF Java EE logging.
I'm using slf4j + log4j with a library of mine.
I am using it in a quick application where I don't really care about configuring the logging... or at least I didn't think I cared.
If I don't configure log4j, I get the standard warning message
log4j:WARN No appenders could be found for logger com.xyz.abcdbabble
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
which is fine.
If I then do
logger.debug("Blah blah blah")
then the logger doesn't print anything out. Great!
But if I do
if (logger.isDebugEnabled())
{
System.out.println("print some complex stuff:");
print_some_complex_stuff();
}
then the stuff in brackets gets executed. What gives?
I'm looking for a way to determine whether to print out something that should have an equivalent enabling to logger.debug(), even if log4j isn't configured in the end application. How can I do this?
Instead of trying to figuring out the logic of the log4j default configuration, I would put in a config file (log4j.properties), like:
log4j.rootLogger=debug, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n
At least this puts you into control.
Instead of bundling with log4j then bundle with the "simple" backend from the slf4j distribution. Then things work as you want them to, and the users cannot tinker.