user2177336
user2177336

Reputation: 205

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

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

Upvotes: 0

Views: 1065

Answers (1)

Matthew Wiley
Matthew Wiley

Reputation: 521

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 :)

Upvotes: 1

Related Questions