Clarity

  • 1.  Accessing log file to identify the error

    Posted Jun 06, 2017 10:46 AM

    I don’t identify the error file, whenever I run the script, I’m getting number of log file in particular folder. Which contains 100 log files (filename.log) How can I identify the error file?

     

    In my idea, we can easy to identify the error file based of File Size.

     

    ( For example : - If the file size is 0KB, content (Error information)  is not available there. Else it may be 5KB or 5MB, the specific file will be considered as an error file)

     

    Do you have any format in XOG/GEL Script for identify the error file.



  • 2.  Re: Accessing log file to identify the error
    Best Answer

    Posted Jun 07, 2017 11:15 AM

    So why don't you scan each of the log files for errors?

     

    Here is an example of scanning the PPM log files.

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
         xmlns:core="jelly:core"
         xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


         <gel:log>Check Log Files Script</gel:log>

         <core:invokeStatic className='java.lang.System' method='getenv' var='NIKU_HOME'>
              <core:arg type='java.lang.String' value='NIKU_HOME' />
         </core:invokeStatic>

         <core:set var="logPath" value="${NIKU_HOME}/logs"/>
         <gel:log>LogPath = ${logPath}</gel:log>

         <core:new className="java.io.File" var="logDir" >
              <core:arg type="java.lang.String" value="${logPath}" />
         </core:new>

         <core:if test="${logDir.isDirectory()}" >
              <core:invoke method="listFiles" on="${logDir}" var="logFiles" />
              <gel:log>Found ${size(logFiles)} log files in ${logPath}</gel:log>

              <core:if test="${size(logFiles)&gt; 0}">
                   <core:set var="lastModifiedFile" value="${logFiles[0]}"/>
                   <core:forEach items="${logFiles}" var="file">
                        <gel:log>Searching ${file.getName()}</gel:log>
                        <core:invokeStatic className='org.apache.commons.io.FileUtils' method='readFileToString' var='fileString'>
                             <core:arg type='java.io.File' value='${file}' />
                        </core:invokeStatic>

                        <core:if test='${fileString.contains("ERROR")}' >
                             <gel:log>*** ERROR in ${file.getName()}</gel:log>

                        </core:if>
                        <core:if test='${fileString.contains("FATAL")}' >
                             <gel:log>*** FATAL in ${file.getName()}</gel:log>
                        </core:if>

                        <core:if test="${lastModifiedFile.lastModified() &lt; file.lastModified()}">
                             <core:set var="lastModifiedFile" value="${file}"/>
                        </core:if>
                   </core:forEach>
                   <gel:log>The latest file is ${lastModifiedFile.getAbsolutePath()}</gel:log>
              </core:if>
         </core:if>

         <gel:log>End Check Log Files Script</gel:log>

    </gel:script>

     

     

     

    V/r,

    Gene



  • 3.  Re: Accessing log file to identify the error

    Posted Aug 15, 2017 12:52 AM

    Thanks you. This is the one which i expected