Append message to JBoss Console using jboss-log4j.xml - jboss

I'm unable to append messages from my application to the JBoss console. The following are the changes that I made to the jboss-log4j.xml configuration file:
<category name="com.tricubes">
<priority value="INFO"/>
<appender-ref ref="CONSOLE"/>
</category>
Here is my code:
public class OneToOneValidation2 {
private static final Logger logger = Logger.getLogger("com.tricubes");
public boolean validate(byte[] fpImage, byte[] fpTemplate, String desc, String ticket) {
...
logger.info("BES INFO: SOCKET MSG SENT " + intToByteArray(x));
...
return b;
}
}
What am I missing?
TIA!
Edited:
The console appender. Also is the default appender used by JBoss.
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
I have tried with both org.jboss.logging.Logger and org.apache.log4j.Logger;

Category is deprecated (use Logger), and Priority is not recommended (use Level). So your config block should be:
<logger name="com.tricubes">
<level value="INFO"/>
<appender-ref ref="CONSOLE"/>
</logger>
Also, what is your CONSOLE appender defined as? If its not pointing at the JBoss console, it wont log there.

Related

Log4j and EAR conflicts with jboss

I have an EAR deployed on Jboss 4.2.3 with the following jboss-app.xml configuration file :
<jboss-app>
<loader-repository>
com.al6:loader=MyProject.ear
<loader-repository-config>java2ParentDelegation=false</loader-repository-config>
</loader-repository>
</jboss-app>
And an application.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
version="1.4">
<description>Manages project business layer</description>
<display-name>MyProject</display-name>
<module>
<ejb>MyProject.jar</ejb>
</module>
</application>
And in my Jboss log file :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!-- ===================================================================== -->
<!-- -->
<!-- Log4j Configuration -->
<!-- -->
<!-- ===================================================================== -->
<!-- $Id: jboss-log4j.xml 75507 2008-07-08 20:15:07Z stan.silvert#jboss.com $ -->
<!--
| For more configuration infromation and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->
<!-- A time/date based rolling appender -->
<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="${jboss.server.log.dir}/server.log"/>
<param name="Append" value="false"/>
<param name="Threshold" value="INFO"/>
<!-- Rollover at midnight each day -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="Target" value="System.out"/>
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message\n -->
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->
<root>
<priority value="INFO" />
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
Until now, all the logging output was using "System....println", which is not a good practice at all.
So, I tried to change to logger.info with :
protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(getClass());
But, after that, I'm not gonna had any log at all, nothing.
I tried to add a category in the jboss log configuration file, like :
<category name="com.myproject">
<priority value="INFO" />
<appender-ref ref="FILE"/>
</category>
But nothing change.
So I used my own log4j implementation observing a log4j.properties file which I can modify without redeploy :
package com.myproject;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class Log4jConfigurator implements Runnable {
private static final Logger logger = Logger.getLogger(Log4jConfigurator.class);
private final Path log4jConfigPath;
public Log4jConfigurator(String log4jConfigFile) {
this.log4jConfigPath = Paths.get(log4jConfigFile).toAbsolutePath();
}
#Override
public void run() {
try {
WatchService watcher = log4jConfigPath.getParent().getFileSystem().newWatchService();
log4jConfigPath.getParent().register(watcher, StandardWatchEventKinds.ENTRY_MODIFY);
while (!Thread.currentThread().isInterrupted()) {
WatchKey key = watcher.take();
for (WatchEvent<?> event : key.pollEvents()) {
if (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY &&
log4jConfigPath.getFileName().toString().equals(event.context().toString())) {
logger.info("Reloading log4j configuration from file: " + log4jConfigPath);
PropertyConfigurator.configure(log4jConfigPath.toString());
}
}
key.reset();
}
} catch (InterruptedException e) {
logger.info("Log4j configuration monitoring thread interrupted.");
} catch (Exception e) {
logger.error("Error while monitoring log4j configuration file", e);
}
}
}
It works perfectly !
BUT, two problems :
1-
I used the same file that Jboss used (server.log), it seems to work but is this ok to write log from jboss and my own log4j in the same file ?
2-
All the log from this are messed up by log4j I presume, and so I had twice informations :
2023-01-25 17:24:44,493 INFO [STDOUT] [ INFO] com.myproject.someBusiness:938 - getOrder
2023-01-25 17:24:44,546 INFO [STDOUT] [ INFO] com.myproject.someBusiness:3138 - prices are refreshed
I already delete the date in log4j xml configuration file to not having twice the log date.
But for the rest (INFO...), it's all contained in the %m variable, so I can't do anything.
Why jboss add it's own prefix ?
Seems to work with this solution :
I put my log4j.properties into /opt/jboss/server/myserverinstance/conf/ directory.
I ask to Jboss to check this log4j.properties file instead of the old jboss-log4j.xml.
In jboss-service.xml :
<!-- ==================================================================== -->
<!-- Log4j Initialization -->
<!-- ==================================================================== -->
<mbean code="org.jboss.logging.Log4jService"
name="jboss.system:type=Log4jService,service=Logging"
xmbean-dd="resource:xmdesc/Log4jService-xmbean.xml">
<attribute name="ConfigurationURL">resource:log4j.properties</attribute>
<attribute name="Log4jQuietMode">true</attribute>
<attribute name="RefreshPeriod">10</attribute>
</mbean>
Then, I let my app check also this same properties file, no change made here.
I put this in my log4.properties file :
#Define root logger options
log4j.rootLogger=INFO, server
log4j.appender.status=org.apache.log4j.DailyRollingFileAppender
log4j.appender.status.File=${jboss.server.log.dir}/status.log
log4j.appender.status.DatePattern='.'yyyy-MM-dd
log4j.appender.status.layout=org.apache.log4j.PatternLayout
log4j.appender.status.layout.ConversionPattern=%d %-5p [%c] %m%n
log4j.appender.server=org.apache.log4j.DailyRollingFileAppender
log4j.appender.server.File=${jboss.server.log.dir}/server.log
log4j.appender.server.DatePattern='.'yyyy-MM-dd
log4j.appender.server.layout=org.apache.log4j.PatternLayout
log4j.appender.server.layout.ConversionPattern=%d %-5p [%c] %m%n
And that's it, it works great,I have both server messages and my app messages, without weird duplicate date, log level or anything.

Scala Slick Driver Logging

I am using the Slick driver with the following versions:
"com.typesafe.slick" %% "slick" % "3.3.1",
"com.typesafe.slick" %% "slick-hikaricp" % "3.3.1"
I have imported these in my class AnimalCounter.scala
import slick.jdbc.PostgresProfile.api._
import slick.jdbc.GetResult
And, I have the following class structure ...
class AnimalCounter {
val db = Database.forConfig("animaldb")
def get(a: Animal): Future[Option[Animal]] =
db.run(....do something......)
def getOrCreate(a: Animal): Future[Option[Animal]] =
db.run(....do something......)
}
So, how do I setup the inbuilt slick logging to log all DB operations that are happening behind the scenes?
Here's the answer on how I got it working. I think #vamsi's approach as mentioned above would work too. However, the important thing to remember in my case was that I needed to remove this dependency since it's designed to supress logs from slick. So please remove this dependency if you already have it.
"org.slf4j" % "slf4j-nop" % "1.7.26"
And after removing the ^^ dependency, please configure your logback.xml like this:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%level] [%date{MM/dd/yyyy HH:mm:ss.SSS}] [SLICK] [%logger{1000}] %green(%X{debugId}) %msg%n</pattern>
</encoder>
</appender>
<root level="${SLICK_LOG_LEVEL:-INFO}">
<appender-ref ref="STDOUT" />
</root>
<logger name="slick.basic.BasicBackend.action" level="${log_action:-inherited}" />
<logger name="slick.basic.BasicBackend.stream" level="${log_stream:-inherited}" />
<logger name="slick.compiler" level="OFF" />
<logger name="slick.compiler.QueryCompiler" level="OFF" />
<logger name="slick.compiler.QueryCompilerBenchmark" level="OFF" />
<logger name="slick.jdbc.DriverDataSource" level="${log_jdbc_driver:-inherited}" />
<logger name="slick.jdbc.JdbcBackend.statement" level="${log_jdbc_statement:-inherited}" />
<logger name="slick.jdbc.JdbcBackend.parameter" level="${log_jdbc_parameter:-inherited}" />
<logger name="slick.jdbc.JdbcBackend.benchmark" level="${log_jdbc_bench:-inherited}" />
<logger name="slick.jdbc.StatementInvoker.result" level="${log_jdbc_result:-inherited}" />
<logger name="slick.jdbc.JdbcModelBuilder" level="${log_createModel:-inherited}" />
<logger name="slick.memory.HeapBackend" level="${log_heap:-inherited}" />
<logger name="slick.memory.QueryInterpreter" level="${log_interpreter:-inherited}" />
<logger name="slick.relational.ResultConverterCompiler" level="${log_resultConverter:-inherited}" />
<logger name="slick.util.AsyncExecutor" level="${log_asyncExecutor:-inherited}" />
</configuration>

How to store logging statements(ex: console.log("some statements")) of Javascript in seprate file in PlayFramewrok application?

I have one Activator project, the controllers which i have written for that i am able to log into seprate file. Now i have some JS file which contains some logging statments too which i want to store in same log file.
Application.java sample
public static Result index() throws Exception {
Logger.of(LoggerConstants.OTNlogger).debug(LoggerConstants.methodEntry);
// CommonUtils.createDBConnection();
if (isSessionExist()) {
Logger.of(LoggerConstants.OTNlogger).debug(
LoggerConstants.returnObj + LoggerConstants.loggerSpace);
Logger.of(LoggerConstants.OTNlogger).debug(
LoggerConstants.methodExit);
return ok(tool.render());
} else {
Logger.of(LoggerConstants.OTNlogger).debug(LoggerConstants.methodExit);
return badRequest(main.render());
}
}
Logger.xml
<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder
by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logFile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- keep 1 days' worth of history -->
<maxHistory>5</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%caller{2} : %r] %p %logger{0} - %msg %n</pattern>
<!-- time, [caller level : excution time of method], level, loggerName, - message -->
</encoder>
</appender>
<logger name="ODE" level="TRACE" additivity="false">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</logger>
<logger name="play" level="INFO" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="info" additivity="false">
<appender-ref ref="STDOUT" />
</root>
LogFile.log sample
15:58:22.491 [Caller+0 at play.Logger$ALogger.debug(Logger.java:332)
Caller+1 at com.egnaro.utils.CommonUtils.createDBConnection(CommonUtils.java:30)
: 81754] DEBUG ODE - Entered into method
15:58:22.512 [Caller+0 at play.Logger$ALogger.info(Logger.java:361)
Caller+1 at com.egnaro.utils.CommonUtils.createDBConnection(CommonUtils.java:33)
: 81775] INFO ODE - Morphia Object Intilizing
15:58:22.927 [Caller+0 at play.Logger$ALogger.info(Logger.java:361)
Caller+1 at com.egnaro.utils.CommonUtils.createDBConnection(CommonUtils.java:46)
: 82190] INFO ODE - Databse created
sample.js
function inputEditor(data, event){
var treeView = $("#tree").data("kendoTreeView");
var selectedNode = treeView.select(),
dataItem = treeView.dataItem(selectedNode);
//var span = $(this).find('.k-sprite').hide();
//var span = $(this).find('.k-sprite').detach();
$target = $(event.target);
$target.editable(function (value, settings)
{
console.log(this);
return value;
},
{
submit:'ok',
event: 'dblclick',
cssclass: 'editableTree'
});
//return;
//$(this).find('.k-sprite').append(span);
$target.trigger('dblclick', [event]);
//$(this).find('.k-sprite').append(span);
}
I want to store log for console.log() in my loggerfile. Please give step by step explanation, i'm new in playframework.

log4j - how to log to seperate/different files

my application is runnig on jboss 7.3. Log4j configuration file looks
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="fileAppender" class="org.apache.log4j.DailyRollingFileAppender">
<param name="encoding" value="UTF-8" />
<param name="append" value="true" />
<param name="file" value="${jboss.server.log.dir}/mainWS.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd HH:mm:ss:SSS} %m rid%X{rid}%n" />
</layout>
</appender>
<appender name="File1" class="org.apache.log4j.DailyRollingFileAppender">
<param name="encoding" value="UTF-8" />
<param name="append" value="true" />
<param name="file" value="${jboss.server.log.dir}/file1.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd HH:mm:ss:SSS} %m rid%X{rid}%n" />
</layout>
</appender>
<appender name="File2" class="org.apache.log4j.DailyRollingFileAppender">
<param name="encoding" value="UTF-8" />
<param name="append" value="true" />
<param name="file" value="${jboss.server.log.dir}/file2.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd HH:mm:ss:SSS} %m rid%X{rid}%n" />
</layout>
</appender>
<appender name="opTimeFile" class="org.apache.log4j.DailyRollingFileAppender">
<param name="encoding" value="UTF-8" />
<param name="append" value="true" />
<param name="file" value="${jboss.server.log.dir}/opTime.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="DEBUG"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %d{yyyy-MM-dd HH:mm:ss:SSS} %m rid%X{rid}%n" />
</layout>
</appender>
<logger name="debugLogger" additivity="false">
<level value="DEBUG" />
<appender-ref ref="fileAppender" />
</logger>
<logger name="Logger1" additivity="false">
<level value="DEBUG" />
<appender-ref ref="File1" />
</logger>
<logger name="Logger2" additivity="false">
<level value="DEBUG" />
<appender-ref ref="File2" />
</logger>
<logger name="opTimeLogger" additivity="false">
<level value="DEBUG" />
<appender-ref ref="opTimeFile" />
</logger>
<root>
<priority value="OFF" />
</root>
files are created in log directory, but loggin only performed in mainWS.log
I've tried
private static final Logger log = Logger.getLogger("debugLogger");
private static final Logger vLog = Logger.getLogger("Logger1");
private static final Logger eLog = Logger.getLogger("Logger2");
private static final Logger tLog = Logger.getLogger("opTimeLogger");
for (Enumeration loggers= LogManager.getCurrentLoggers(); loggers.hasMoreElements(); ) {
Logger logger = (Logger) loggers.nextElement();
log.debug("logger - " + logger.getName());
vLog.debug("vLogger - " + logger.getName());
eLog.debug("eLogger - " + logger.getName());
tLog.debug("tLogger - " + logger.getName());
for (Enumeration appenders=logger.getAllAppenders(); appenders.hasMoreElements(); ) {
Appender appender = (Appender) appenders.nextElement();
log.debug("appender - " + appender.getName());
vLog.debug("vAppender - " + appender.getName());
eLog.debug("eAppender - " + appender.getName());
tLog.debug("tAppender - " + appender.getName());
}
}
but result is only in mainWS.log file
DEBUG 2014-11-13 10:29:03:125 logger - rid
DEBUG 2014-11-13 10:29:03:138 logger - opTimeLogger rid
DEBUG 2014-11-13 10:29:03:138 logger - Logger1 rid
DEBUG 2014-11-13 10:29:03:138 logger - debugLogger rid
DEBUG 2014-11-13 10:29:03:138 appender - fileAppender rid
DEBUG 2014-11-13 10:29:03:139 logger - Logger2 rid
it seems that only debugLogger has an appender.
Any ideas?
I guess there was a conflict between log4j and the default logging implementation of the application server. I had to exclude the module from your deployment.
I added a WEB-INF/jboss-deployment-structure.xml file
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
</exclusions>
</deployment>
I had to include log4j libraries in my application classpath as well.
now it works
My first guess is that log4j reads a different config file than you expect. Check the debug output of log4j when it starts and especially the paths in there.

GWT remote logging going to System.out instead of log file

I have setup gwt remote logging based on the gwt documentation, however my logs are going to System.out instead of being written to a log file.
My gwt module looks like:
<module rename-to='ezdappserver'>
<inherits name="com.google.gwt.logging.Logging"/>
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
<set-property name="gwt.logging.logLevel" value="FINEST"/>
<set-property name="gwt.logging.enabled" value="TRUE"/>
<set-property name="gwt.logging.consoleHandler" value="ENABLED" />
<set-property name="gwt.logging.popupHandler" value="DISABLED" />
</module>
My servlet definition is setup like:
<servlet>
<servlet-name>remoteLogging</servlet-name>
<servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>remoteLogging</servlet-name>
<url-pattern>/ezdappserver/remote_logging</url-pattern>
</servlet-mapping>
When an error is logged I see output in my console like so:
Mar 26, 2014 2:10:36 PM com.google.gwt.logging.server.RemoteLoggingServiceUtil logOnServer
SEVERE: Exception caught: (NotFoundError)
....Rest of error....
I was expecting this output to be written to a log file somewhere in my war. Also, I would really like to be able to specify where this file is located, however I haven't been able to find any documentation on that either.
Any help would be much appreciated.
NOTE: I am not running this through dev mode, this is with compiled code.
Thanks!
Try below options also in gwt.xml based on your requirement:
<!-- This handler sends log messages to the server, where they will be logged using the server side logging mechanism. -->
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
<!-- Logs by calling method GWT.log. These messages can only be seen in Development Mode in the DevMode window. -->
<set-property name="gwt.logging.developmentModeHandler" value="ENABLED" />
<!-- These messages can only be seen in Development Mode in the DevMode window. -->
<set-property name="gwt.logging.systemHandler" value="ENABLED" />
<!-- Logs to the popup which resides in the upper left hand corner of application when this handler is enabled. -->
<set-property name="gwt.logging.popupHandler" value="DISABLED" />
<!-- Logs to the javascript console, which is used by Firebug Lite (for IE), Safari and Chrome. -->
<set-property name="gwt.logging.consoleHandler" value="DISABLED"/>
<!-- Logs to the firebug console. -->
<set-property name="gwt.logging.firebugHandler" value="DISABLED" />
If above configuration are still not working for you then try below code along with above configuration.
Add log4j.xml file to define the log file location with log level
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="DT=> %d [%.4t] %-5p %c{1} - %m%n" />
</layout>
</appender>
<appender name="SERVER_FILE_LOG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${jboss.server.log.dir}/logs/DataTools_Server.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="5MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%.4t] %-5p [%c] %m%n" />
</layout>
</appender>
<appender name="CLIENT_FILE_LOG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${jboss.server.log.dir}/logs/DataTools_Client.log" />
<param name="Append" value="true" />
<param name="MaxFileSize" value="5MB" />
<param name="MaxBackupIndex" value="10" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%.4t] %-5p %m%n" />
</layout>
</appender>
<category name="com.x.y.server">
<priority value="DEBUG" />
<appender-ref ref="SERVER_FILE_LOG" />
<appender-ref ref="STDOUT" />
</category>
<category name="gwtRemoteLogging">
<priority value="ERROR" />
<appender-ref ref="CLIENT_FILE_LOG" />
</category>
<root>
<priority value ="ERROR" />
<appender-ref ref="SERVER_FILE_LOG" />
</root>
</log4j:configuration>
Define you own logging servlet by implementing RemoteLoggingService
import java.util.logging.Level;
import java.util.logging.LogRecord;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import com.google.gwt.logging.server.StackTraceDeobfuscator;
import com.google.gwt.logging.shared.RemoteLoggingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.apache.log4j.Logger;
/**
* The Class GwtRemoteLogging.
*/
#SuppressWarnings("serial")
public class GwtRemoteLogging extends RemoteServiceServlet implements RemoteLoggingService {
/** The Constant logger. */
private StackTraceDeobfuscator deobfuscator = null;
private final static Logger logger = Logger.getLogger("gwtRemoteLogging");
#Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/**
* Logs a Log Record which has been serialized using GWT RPC on the server.
*
* #return either an error message, or null if logging is successful.
*/
public final String logOnServer(LogRecord lr) {
try {
if (lr.getLevel().equals(Level.SEVERE)) {
logger.error(lr.getMessage(),lr.getThrown());
} else if (lr.getLevel().equals(Level.INFO)) {
logger.info(lr.getMessage(),lr.getThrown());
} else if (lr.getLevel().equals(Level.WARNING)) {
logger.warn(lr.getMessage(),lr.getThrown());
} else if (lr.getLevel().equals(Level.FINE)) {
logger.debug(lr.getMessage(),lr.getThrown());
} else {
logger.trace(lr.getMessage(),lr.getThrown());
}
} catch (Exception e) {
logger.error("Remote logging failed", e);
return "Remote logging failed, check stack trace for details.";
}
return null;
}
/**
* By default, this service does not do any deobfuscation. In order to do server side
* deobfuscation, you must copy the symbolMaps files to a directory visible to the server and
* set the directory using this method.
*
* #param symbolMapsDir
*/
public void setSymbolMapsDirectory(String symbolMapsDir) {
if (deobfuscator == null) {
deobfuscator = new StackTraceDeobfuscator(symbolMapsDir);
} else {
deobfuscator.setSymbolMapsDirectory(symbolMapsDir);
}
}
}
web.xml
<servlet>
<servlet-name>remoteLogServlet</servlet-name>
<servlet-class>com.x.y.server.servlet.GwtRemoteLogging</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>remoteLogServlet</servlet-name>
<url-pattern>/ezdappserver/remote_logging</url-pattern>
</servlet-mapping>
The RemoteServiceServlet uses java.util.logging to log, and by default it logs to the console (System.err, not System.out BTW).
If you want to log to a file, then you have to configure java.util.logging; either editing your global lib/logging.properties (not recommended), using your own config file that you pass to the JVM using the java.util.logging.config.file system property, or programmatically.
Depending on your servlet container, it can be configured by different means. For instance, Tomcat will read a logging.properties file in your WEB-INF/classes: http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_java.util.logging_(default)