admin管理员组

文章数量:1338664

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.alfresco.repo.web.scripts=warn
log4j.logger.alfresco.repo.web.scripts.BaseWebScriptTest=info
log4j.logger.alfresco.repo.web.scripts.AlfrescoRhinoScriptDebugger=off
log4j.logger.alfresco.repo.jscript=debug
log4j.logger.alfresco.repo.jscript.ScriptLogger=debug
log4j.logger.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?

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.alfresco.repo.web.scripts=warn
log4j.logger.alfresco.repo.web.scripts.BaseWebScriptTest=info
log4j.logger.alfresco.repo.web.scripts.AlfrescoRhinoScriptDebugger=off
log4j.logger.alfresco.repo.jscript=debug
log4j.logger.alfresco.repo.jscript.ScriptLogger=debug
log4j.logger.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?

Share Improve this question asked Sep 18, 2013 at 12:23 user2554076user2554076 773 silver badges8 bronze badges 1
  • In which context is your JS script running? alfresco or share? It seems to be a SURF/Share JS - so by default your log output will be in share.log – alfrescian Commented Sep 19, 2013 at 8:44
Add a ment  | 

2 Answers 2

Reset to default 14

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.springframework.extensions.webscripts.ScriptLogger=debug

to 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.

本文标签: javascriptloggerlog is not logging to alfrescologStack Overflow