Write AMP log into a separate logger file?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2014 07:27 AM
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
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
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2014 11:14 PM
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
then configure you module class to use the appender.
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2014 05:11 AM
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:
In the first file:
In the second file:
In the java code:
The error still was logged in alfresco.log file.
Can you help?
Many thanks,
Sun
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2014 05:33 AM
1.First you must place your log4j.properties file in correct location,you should place and name it under following pattern
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.
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2014 08:27 AM
Thanks very much. I have used the second section of your settings, as the first section makes the programming not running properly.
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.
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.
