Logger configuration

cancel
Showing results for 
Search instead for 
Did you mean: 
Established Member

Logger configuration

Jump to solution

Hi there ,

Is there  a specific onfiguration for logger to print log.info() message  ?   I have action classes extended quatz class as shown below .  but the log is not printing out in log file - alfresco.log . I can see system.out.println in tomcat log .

please let me know if there are any configuration changes reuired in log4j.properties  ? I have kept all the config default didnt make any changes in log4j

 

image.png

 

2 Solutions

Accepted Solutions
Moderator
Moderator

Re: Logger configuration

Jump to solution

Is there a reason why you had to extend Object class ? 

Have you enabled logging for your package or class in log4j.properties? If not, Try adding log setting in following format:

log4j.logger.com.github.mycms.action=INFO

where "com.github.mycms.action" is the package where you class resides. 

OR

log4j.logger.com.github.mycms.action.MoveMonthlyDataAction=INFO

where "com.github.mycms.action.MoveMonthlyDataAction" is the fqn of the class. 

You can add the settings either in :

$TOMCAT_HOME/shared/classes/alfresco/extension/custom-log4j.properties

OR

You can add the settings either in your custom module which you are applying to alfresco.war:

<yourCustomModule>/src/main/resources/alfresco/module/<custom-module>/log4j.properties

OR

Use admin console to add the log settings, if you are using enterprise version (Note, when you restart server these settings won't persist):

http://<HOST : PORT>/alfresco/s/enterprise/admin/admin-log-settings

~Abhinav
(ACSCE, AWS SAA-C02, GAIQ)

View solution in original post

Master

Re: Logger configuration

Jump to solution

One thing I have noticed in your job class is that you are using JUL instead of Log4J, Commons Logging, or - way more ideal - SLF4J. While Commons Logging and SLF4J are both set up to log via Log4J in the backend, I do not think that JUL is set up in the same way. I can only recommend to ALWAYS use SLF4J logging APIs to ensure that a) you are logging to the same file(s) that Alfresco logs to and b) you are not dependent on any specific log backend implementation, and could switch to whatever (e.g. I switched to Logback instead of Log4J in one project).

Also, everything you output via System.out will land in the catalina.out, unless you configure Tomcat to ignore System.out. Generally speaking though, System.out should be forbidden under threat of severe penalties...

View solution in original post

8 Replies
Moderator
Moderator

Re: Logger configuration

Jump to solution

Is there a reason why you had to extend Object class ? 

Have you enabled logging for your package or class in log4j.properties? If not, Try adding log setting in following format:

log4j.logger.com.github.mycms.action=INFO

where "com.github.mycms.action" is the package where you class resides. 

OR

log4j.logger.com.github.mycms.action.MoveMonthlyDataAction=INFO

where "com.github.mycms.action.MoveMonthlyDataAction" is the fqn of the class. 

You can add the settings either in :

$TOMCAT_HOME/shared/classes/alfresco/extension/custom-log4j.properties

OR

You can add the settings either in your custom module which you are applying to alfresco.war:

<yourCustomModule>/src/main/resources/alfresco/module/<custom-module>/log4j.properties

OR

Use admin console to add the log settings, if you are using enterprise version (Note, when you restart server these settings won't persist):

http://<HOST : PORT>/alfresco/s/enterprise/admin/admin-log-settings

~Abhinav
(ACSCE, AWS SAA-C02, GAIQ)

View solution in original post

Community Manager
Community Manager

Re: Logger configuration

Jump to solution

Hi @brijeshnk,

Just a note about the name of your class - there is no such word as "monthily" in the English language. I think you mean "monthly"? So it might be worth renaming your class to MoveMonthlyDataAction, and the methods accordingly - MoveMonthlyDataThreadRunner, setMoveMonthlyDataThreadRunner, etc. This may make usage and maintenance of your code easier in the long run.

HTH,  

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
Established Member

Re: Logger configuration

Jump to solution

thanks for alerting this :-)

Established Member

Re: Logger configuration

Jump to solution

Hi thanks a lot for the response. I have configured this as mentioned below

I  have added following configuration in  $TOMCAT_HOME/shared/classes/alfresco/extension/custom-log4j.properties

log4j.logger.com.uia.archive.movedata.MoveMonthilyDataAction=INFO
log4j.logger.com.uia.archive.movedata.MoveMonthilyDataThreadRunner=INFO
log4j.logger.com.uia.archive.movedata.MoveMonthilyData=INFO

Result was :-

logs are printing out , but the in different  logs. ( alfresco.lg and alfrescotomcat-stdout.2020-02-20.log)

logs from 'com.uia.archive.movedata.MoveMonthilyDataAction'  class is printed in 'alfreso.log'.

Other class logs are printed in 'alfrescotomcat-stdout.2020-02-20.log'  . Though all classes are same package and location . 

Is there any specific reason for this or this behaviour is expected  ?

thanks a lot

Master

Re: Logger configuration

Jump to solution

One thing I have noticed in your job class is that you are using JUL instead of Log4J, Commons Logging, or - way more ideal - SLF4J. While Commons Logging and SLF4J are both set up to log via Log4J in the backend, I do not think that JUL is set up in the same way. I can only recommend to ALWAYS use SLF4J logging APIs to ensure that a) you are logging to the same file(s) that Alfresco logs to and b) you are not dependent on any specific log backend implementation, and could switch to whatever (e.g. I switched to Logback instead of Log4J in one project).

Also, everything you output via System.out will land in the catalina.out, unless you configure Tomcat to ignore System.out. Generally speaking though, System.out should be forbidden under threat of severe penalties...

View solution in original post

Established Member

Re: Logger configuration

Jump to solution

@afaust  , Awesome !

that was perfect .    I was using multiple logging package. I replaced all with log4j packages in all classes ,  All logs is are now visible in alfresco.log. 

thanks a lot for this answer

Brijesh 

Community Manager
Community Manager

Re: Logger configuration

Jump to solution

Hi @brijeshnk,

Thanks for reporting back on how @afaust helped you out - this feedback is really useful for other users encountering similar problems. 

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
Senior Member

Re: Logger configuration

Jump to solution

Just a more or less generic question: Do we really want to discuss such basic programming questions here in the Alfresco forum? We're all busy people and I would appreciate it to focus on questions with stronger Alfresco focus and apply some rules similar to stack overflow ...