cancel
Showing results for 
Search instead for 
Did you mean: 

Write AMP log into a separate logger file?

sunquanbin
Champ on-the-rise
Champ on-the-rise
Hi,

I'm currently using the "org.apache.log4j.Logger" to write logs in the Java controllers of web scripts for the AMP I'm working on.

I have noticed that the logs are written in "Alfresco.log" file. It is possible that I can write logs of an AMP into a separate file, e.g. my_amp.log?

Regards,

Sun
4 REPLIES 4

kaynezhang
World-Class Innovator
World-Class Innovator
Of course you can,it is the same with configuring separate log file for different categories in log4j.
Just create a log4j configure file for your module,
in your log4j file configure a new file appender,for example
log4j.appender.moduleLog=org.apache.log4j.FileAppenderlog4j.appender.moduleLog.File=yourmodule.loglog4j.appender.moduleLog.layout=org.apache.log4j.PatternLayoutlog4j.appender.moduleLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n‍‍‍‍‍‍

then configure you module class to use the appender.
log4j.logger.com.yourcompany.your.module=info,moduleLog‍‍‍



sunquanbin
Champ on-the-rise
Champ on-the-rise
Hi kaynezhang,

Thanks for the reply, but I cannot get it to work. In the built amp file, I have two two log4j.properties files in the following path:

1: my_module_id.amp\log4j.properties2: my_module_id.amp\config\alfresco\module\my_module_id\‍‍‍‍


In the first file:
log4j.logger.my_module_id=info,moduleLog‍‍


In the second file:
log4j.appender.moduleLog=org.apache.log4j.FileAppenderlog4j.appender.moduleLog.File=my_module_id.loglog4j.appender.moduleLog.layout=org.apache.log4j.PatternLayoutlog4j.appender.moduleLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n‍‍‍‍‍‍‍‍‍


In the java code:
logger.error("test error msg");‍


The error still was logged in alfresco.log file.

Can you help?

Many thanks,

Sun

kaynezhang
World-Class Innovator
World-Class Innovator
1.First you must place your log4j.properties file in correct location,you should place and name it under following pattern
classpath*:alfresco/module/*/log4j.properties‍‍‍


2.Second why did you separate your module log4j configuration into two files ? following is a sample module log4j config file,you can copy and past it into your amp log4j.properties .it should work.
log4j.rootLogger=TRACE, stdoutlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d [%24F:%t:%L] - %m%nlog4j.appender.moduleLog=org.apache.log4j.FileAppenderlog4j.appender.moduleLog.File=my_module_id.loglog4j.appender.moduleLog.layout=org.apache.log4j.PatternLayoutlog4j.appender.moduleLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%nlog4j.logger.com.yourcompany.your.custom.demo=info,moduleLog‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thanks very much. I have used the second section of your settings, as the first section makes the programming not running properly.
log4j.appender.moduleLog=org.apache.log4j.FileAppenderlog4j.appender.moduleLog.File=my_module_id.loglog4j.appender.moduleLog.layout=org.apache.log4j.PatternLayoutlog4j.appender.moduleLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n log4j.logger.com.yourcompany.your.custom.demo=info,moduleLog‍‍‍‍‍‍‍‍‍‍‍‍


I now only use 1 file in the path you specified. It works now.

The reason to have 2 files it's because I'm using the Maven alfresco SDK and it comes with 2 files.