It's all about the answers!

Ask a question

How to log informarion in plugin?


Avinash Bamane (20115) | asked Nov 25 '15, 6:58 a.m.
Hello,
In my plugin, I want maintain log for some activities. How can I add my comments as a log to logs/ccm.log? Also is it possible to maintain separate log file in separate folder(not in ccm.log)? If yes, how can it be done?

Thanks.

Accepted answer


permanent link
Michele Pegoraro (1.8k14118103) | answered Nov 25 '15, 7:37 a.m.
On server side, extending the AbstractService class you have the getLog() method that permits to log.
The configuration of the log are managed by log4j.properties file stored in your application configuration folder (like JAZZ_HOME/server/conf/ccm). You can use this file to manage which level log and for which class and what file use to store. I generally use a separated log file for the extensions.
Avinash Bamane selected this answer as the correct answer

Comments
Avinash Bamane commented Nov 26 '15, 5:50 a.m.

Hello Michele,
Thanks for the reply!!
It really helps a lot. But, I have some doubts.
I have created my own FileAppender as below,
log4j.rootLogger=DEBUG, file, tempinfo

existing RTC appender


log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=5
log4j.appender.file.File=logs/ccm.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} [%30t] %5p %-50.50c  - %m%n

my appender


log4j.appender.tempinfo=org.apache.log4j.RollingFileAppender
log4j.appender.tempinfo.MaxFileSize=10MB
log4j.appender.tempinfo.MaxBackupIndex=15
log4j.appender.tempinfo.File=logs/temp.log
log4j.appender.tempinfo.layout=org.apache.log4j.PatternLayout
log4j.appender.tempinfo.layout.ConversionPattern=%d{ISO8601} [%30t] %5p %-50.50c  - %m%n

I want to have 2 separate log files. One is ccm.log file which will have all RTC related logs and one temp.log, which will have only my plugin logs. How to achieve this?
Thanks


Michele Pegoraro commented Nov 26 '15, 6:06 a.m.

You have to enable your class to log in the second file:

log4j.logger.yourextensionid=DEBUG,tempinfo

yourextensionid must be the component id you've put on the plugin.xml for the extension service. If you have a single componentId for every extension you just need to put that one otherwise any componentId will be needed (you can also use the initial part of the componentId, for example com.yourorg.yourpackage will log both com.yourorg.yourpackage.extension1 and com.yourorg.yourpackage.extension2). And remove tempinfo from rootLogger otherwise you will have ccm logs inside your file too.
Any other configuration is log4j related so take a look to https://logging.apache.org/log4j/1.2/manual.html


Avinash Bamane commented Nov 26 '15, 6:28 a.m.

Hello Michele,
Got it !! Yes, my plugins have unique component ids for every extension. Now, I am able to have separate log files. Thanks a lot !!

One other answer



permanent link
Michele Pegoraro (1.8k14118103) | answered Nov 25 '15, 7:36 a.m.
On server side, extending the AbstractService class you have the getLog() method that permits to log.
The configuration of the log are managed by log4j.properties file stored in your application configuration folder (like JAZZ_HOME/server/conf/ccm). You can use this file to manage which level log and for which class and what file use to store. I generally use a separated log file for the extensions.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.