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?
Looks like you got confused with what applies to the repository and what applies to share.
In the repository:
logger.log
uses the categoryorg.alfresco.repo.jscript.ScriptLogger
at level debug, so what you have incustom-log4j.properties
is correct (the appender is ignored though). Make sure it is in the classpath atalfresco/extension
. The directorytomcat/shared/classes/alfresco/extension
is what you usually want.In share:
logger.log
uses the categoryorg.springframework.extensions.webscripts.ScriptLogger
. As far as I remember, there is no "custom-log4j property configuration mechanism" available there, so you'll have to appendto
share/WEB-INF/classes/log4j.properties
.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.