Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logger.log is not logging to alfresco.log

I am trying to use logger.log("Hello") in a javascript file corresponding to a template page in Alfresco.

I have set the following: - in custom-log4j.properties (overriding log4j.properties)

log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=alfresco.log
log4j.appender.File.Append=true
log4j.appender.File.DatePattern='.'yyyy-MM-dd
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n

log4j.logger.org.alfresco.repo.web.scripts=warn
log4j.logger.org.alfresco.repo.web.scripts.BaseWebScriptTest=info
log4j.logger.org.alfresco.repo.web.scripts.AlfrescoRhinoScriptDebugger=off
log4j.logger.org.alfresco.repo.jscript=debug
log4j.logger.org.alfresco.repo.jscript.ScriptLogger=debug
log4j.logger.org.alfresco.repo.cmis.rest.CMISTest=info

But when I use logger.log in the js file, I get logger is not defined.

The solution was to set the following in custom-slingshot-application-context.xml

<bean id="webframework.rendition.processor.webtemplate" class="org.springframework.extensions.webscripts.WebTemplateProcessor">
      <property name="templateProcessorRegistry" ref="webframework.templates.registry.templateprocessor" />
      <property name="scriptProcessorRegistry"   ref="webframework.templates.registry.scriptprocessor" />
      <property name="processorModelHelper"      ref="processor.model.helper"></property>
      <property name="webFrameworkConfigElement" ref="webframework.config.element"></property>
      <property name="scriptObjects">
         <map>
            <entry key="remote" value-ref="webframework.webscripts.scriptremote" />
            <entry key="stringUtils">
               <bean class="org.springframework.extensions.webscripts.ScriptableUtils"/>
            </entry>
            <entry key="logger">
               <bean class="org.springframework.extensions.webscripts.ScriptLogger"/>
            </entry>
         </map>
      </property>
   </bean>

Now using logger.log does not give any error, but it seems that it's not writing to alfresco.log which is located in Tomcat/bin

Does anybody have a clue?

like image 636
user2554076 Avatar asked Sep 18 '13 12:09

user2554076


2 Answers

Looks like you got confused with what applies to the repository and what applies to share.

In the repository:

logger.log uses the category org.alfresco.repo.jscript.ScriptLogger at level debug, so what you have in custom-log4j.properties is correct (the appender is ignored though). Make sure it is in the classpath at alfresco/extension. The directory tomcat/shared/classes/alfresco/extension is what you usually want.

In share:

logger.log uses the category org.springframework.extensions.webscripts.ScriptLogger. As far as I remember, there is no "custom-log4j property configuration mechanism" available there, so you'll have to append

log4j.logger.org.springframework.extensions.webscripts.ScriptLogger=debug

to share/WEB-INF/classes/log4j.properties.

like image 75
Andreas Steffan Avatar answered Sep 30 '22 13:09

Andreas Steffan


If you don't want to restart alfresco and execute your script in repository, there is another way as work-around solution. Try to use logger.system.out other than logger.log and you will still find the logging message in catalina.out.

like image 36
Johnson Jian Avatar answered Sep 30 '22 12:09

Johnson Jian