Forum Discussion

deepesh_jain's avatar
deepesh_jain
Frequent Contributor
13 years ago

Logging to a file.

Hello,

I have a bunch of test scripts and am using log.info "" to see the output on the log Output portion of the screen. However, now i want to log all the output to file. I don't want to use the PrintWriter as it would require lot of rework. Is there a way, i can define the at the root level so that all these calls are redirected directly to a file?

Thanks,
Deepesh

4 Replies

  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    Okay, I figured log4j.xml file in the soapui bin directory can be updated. However, I am looking to add a node which will result all the output on "scriptlog" in soapui to be sent to File mentioned in log4j.xml.

    I guess i need logger name for that. I tried following but it didnt work:

    <logger name = "soapui.scriptlog">
    <level value="INFO" />
    <appender-ref ref="FILE2"/>
    </logger>
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    I actually was able to get it to work by updating the following from a different post in log4j.xml:

    <appender name="GroovyFile" class="org.apache.log4j.FileAppender">
    <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
    <param name="File" value="C:\\Documents and Settings\\jainde\\Desktop\\prj\\mylog.log"/>
    <param name="Threshold" value="DEBUG"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p [%c{1}] %m%n"/>
    </layout>
    </appender>

    <logger name="groovy.log">
    <appender-ref ref="GroovyFile"/>
    </logger>
  • brext2005's avatar
    brext2005
    New Contributor
    deepesh.jain wrote:
    <appender name="GroovyFile" class="org.apache.log4j.FileAppender">
    <errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler"/>
    <param name="File" value="C:\\Documents and Settings\\jainde\\Desktop\\prj\\mylog.log"/>
    <param name="Threshold" value="DEBUG"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p [%c{1}] %m%n"/>
    </layout>
    </appender>

    <logger name="groovy.log">
    <appender-ref ref="GroovyFile"/>
    </logger>


    Did you replace the original values in the .xml? And how you invoke this logger from your script? Thanks.
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    Hi,

    You can just include the code i included in the log4j xml file. Now whenever you invoke log.info, it will redirect all output to log file.

    Regards,
    Deepesh Jain