how to write log4j-gwt messages into a file instead of console? - gwt

I am using log4j-gwt aud gwt's remote logging. I get the messages logged on my console as expected but did not managed to get the message print on my physical .log file.
Any idea of how I can do this?
Here is my log4j properties file (which works fine for all non-gwt related messages):
# CONSOLE APPENDER CONFIG [common] ---------------------------------------------------------------
log4j.appender.CONSOLE_APPENDER=org.apache.log4j.ConsoleAppender
#log4j.appender.CONSOLE_APPENDER.layout=org.apache.log4j.SimpleLayout
log4j.appender.CONSOLE_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE_APPENDER.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# ROOT LOGGER CONFIG ----------------------------------------------------------------------
log4j.rootLogger=DEBUG,ROOT_FILE_APPENDER
log4j.appender.ROOT_FILE_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.ROOT_FILE_APPENDER.File=C:/log/tbps_root.log
log4j.appender.ROOT_FILE_APPENDER.MaxFileSize=20480KB
log4j.appender.ROOT_FILE_APPENDER.MaxBackupIndex=5
log4j.appender.ROOT_FILE_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.ROOT_FILE_APPENDER.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# GWT -------------------------------------------------------------------------------------
#These are various unseccsful attemps...
log4j.logger.com.google.gwt.logging.server.RemoteLoggingServiceUtil=DEBUG,ROOT_FILE_APPENDER
log4j.logger.com.google.gwt.logging.server.RemoteServiceServlet=DEBUG,ROOT_FILE_APPENDER
log4j.logger.com.google.gwt.logging.server.simpleRemoteHandler=DEBUG,ROOT_FILE_APPENDER
log4j.logger.com.google.gwt.logging=DEBUG,ROOT_FILE_APPENDER
log4j.logger.com.google.gwt.logging.Logging=DEBUG,ROOT_FILE_APPENDER
log4j.logger.com.google.gwt.logging.server=DEBUG,ROOT_FILE_APPENDER

GWT-log4j and GWT's RemoteLoggingService use different loggers, as described here. Hence, your log4j properties are not being applied to GWT's remote logger.
You can either implement your own remote logging class, or use slf4j to "bridge" the two loggers.
I recently added logs of the user's actions to a GWT application. I first tried using GWT-log4j in conjunction with RemoteLoggingService and had this same issue. After reading the above link I created my own logger class -- this was particularly nice as I could pass data objects to the remote logger allowing me to serialize the state of the GWT application. This later became very useful :)

Related

Enable TRACE for a particular logger in ActiveMQ Artemis

How do I setup logging.properties to log diverts in artemis.log?
I understand that TRACE should be used for org.apache.activemq.artemis.core.server.impl.DivertImpl
How do I set it up in etc/logging.properties?
To enable a particular logger (e.g. org.apache.activemq.artemis.core.server.impl.DivertImpl) in logging.properties you must first add the logger to the loggers list at the top of the file. Here is the default loggers list with org.apache.activemq.artemis.core.server.impl.DivertImpl added:
loggers=org.eclipse.jetty,org.jboss.logging,org.apache.activemq.artemis.core.server,org.apache.activemq.artemis.utils,org.apache.activemq.artemis.journal,org.apache.activemq.artemis.jms.server,org.apache.activemq.artemis.integration.bootstrap,org.apache.activemq.audit.base,org.apache.activemq.audit.message,org.apache.activemq.audit.resource,org.apache.activemq.artemis.core.server.impl.DivertImpl
Then you need to configure the logging level for the logger to TRACE, e.g.:
logger.org.apache.activemq.artemis.core.server.impl.DivertImpl.level=TRACE
Lastly, you need to update the level of the necessary handler to allow the TRACE logging through, e.g.:
handler.CONSOLE.level=TRACE
or
handler.FILE.level=TRACE

How to enable log4j for Usergrid

I deployed usergrid in tomcat, I see it is using slf4j binds to log4j, I tried to put log4j.properties in /var/lib/tomcat7/webapps/ROOT/WEB-INF/classes$ , but still not seeing log file created? anyone could help?
Usergrid is here, github.com/apache/incubator-usergrid
I built it myself and put the ROOT.war in tomcat /var/lib/tomcat7/webapps/, trying to enable logs in usergrid, I see a lot of log.info in usergrid's code, then I put log4j.properties in /var/lib/tomcat7/webapps/ROOT/WEB-INF/classes, but log file is not created
# Root logger option
log4j.rootLogger=INFO, file
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
#Redirect to Tomcat logs folder
log4j.appender.file.File=${catalina.home}/logs/logging.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
I've been able to configure Log4j logging in Usergrid by adding the following to Tomcat's CATALINA_OPTS environment variable:
-Dlog4j.configuration=file:/${path}/log4j.properties
Where ${path} is the path to your Log4j properties file.

log4j2 logfile location, one for local Eclipse Dev one during deploy

I'm using log4j2 and have a rolling file configured in log4j2.xml as
<RollingFile name="a2.log" append="true"
fileName="C:/Dev/error_log/local_error_log_app_name.log"
filePattern="C:/Dev/error_log/local_error_log_app_name_-%d{MM-dd-yyyy}-%i.txt.gz">
This is good for local Eclipse Development but when I deploy to a JBOSS server I'd like the path and filename to be appropriate for that file system, without having to remember to edit the log4j2.xml file before deploying.
fileName="/www/logs/error_log/error_log_app_name.log"
I've seen the following posts
How to give dynamic file name in the appender in log4j.xml
Log4J2 - assigning file appender filename at runtime
and tried
fileName="$${sys:logFilename}" and fileName="${sys:logFilename}" but all that did was put a file ${sys in the Jboss bin folder `jboss-as-7.1.1.Final\bin'
Have you tried declaring a property in your config file?
The log4j2 docs have an example here:
http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution
If this does not work, please raise a ticket in the log4j2 issue tracker:
https://issues.apache.org/jira/browse/LOG4J2
When declaring a property in log4j2.xml, use double dollar signs $$
<Properties>
<Property name="filenameVariable">$${sys:errorLogFileName}</Property>
<Property name="filePatternVariable">$${sys:errorLogFilePattern}</Property>
</Properties>
and reference using single dollar sign $
<RollingFile name="a2.log" append="true"
fileName="${filename}"
filePattern="${filePattern}">
However it is not necessary to use a property. Just reference the system property directly, again with just single dollar sign
<RollingFile name="a2.log" append="true"
fileName="${sys:errorLogFileName}"
filePattern="${sys:errorLogFilePattern}">
And to the answer to my actual issue how to dynamically specify log file based on whether I am running locally in Eclipse or deployed to our server, I'm using
#Singleton
#Startup
public class StartupBean {
#PostConstruct
private void startup() {
if (File("C:/").exists()) {
System.setProperty("errorLogFileName", "C:/path/to/error_log.txt");
System.setProperty("errorLogFilePattern", "C:/path/to/error_log-%d{MM-dd-yyyy}-%i.txt.gz");
} else {
System.setProperty("errorLogFileName", "/unix/path/to/error_log.txt");
System.setProperty("errorLogFilePattern", "/unix/path/to/error_log-%d{MM-dd-yyyy}-%i.txt.gz");
}
}
}
Important! Without a system property set System.setProperty("whatever") the lookup in your log4j2.xml will fail and instead log4j will write to a file named as the first part of your lookup before the semicolon i.e. ${sys

Logback + Wildfly 8 - incorrect pattern

I have a problem with logback + wildfly 8 configuration.
I'm using simple ConsoleAppender:
appender("STDOUT", ConsoleAppender) {
encoder(PatternLayoutEncoder) {
pattern = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{70} - %msg%n"
}
}
logger("com.package.app", INFO)
root(DEBUG, ["STDOUT"])
The problem is that Wildfly appends to logback messages also server's log pattern.
It looks like:
11:31:49,954 INFO [stdout] (default task-1) 11:31:49.951 [default task-1] INFO com.package.app.controller.FrontController - message...
As You can see, there is a server logs pattern first and then the logback message
How to solve this problem?
WildFly captures System.out and System.err and redirects them to a logger. You could configure a logger in WildFly with the name stdout, set the use-parent-handlers attribute to false and set the level to NONE. This should disable System.out from printing which means it will also not appear in the server.log.
That said, I don't see a reason to use logback for a ConsoleAppender since the server already provides one.

Drools logging with logback

I'm using Drools 5.4.0.Final
For logging I'm using logback in my application.
I tried to add update my logback.xml with
<logger name="org.drools" level="debug"/>
But I see nothing in my logs concerning Drools.
I would expect to see so my lines of logs concerning the drools initialization.
You can pass the LOGGER to the StatefulKnowledgeSession
private static final Logger LOGGER = LoggerFactory.getLogger(Example.class);
private transient StatefulKnowledgeSession ksession;
.
.
.
ksession.setGlobal("logger", LOGGER);
and in your DRL file, you have to define global org.slf4j.Logger logger and then you can use the logger in your rules.
Drools 5.4.0.Final does not support any logging framework natively. The next version, Drools 5.5.0.Beta1, will. It will also be documented in the manual how to use it. See this issue for more info.
Drools 5.5.0.Beta1 will log to slf4j-api, so you can logback, log4j, jdk-logging, slf4j-simple, ... You still need to explicitly call KnowledgeRuntimeLoggerFactory.newConsoleLogger() and add that to the event listeners.