Class LogUtils


  • public class LogUtils
    extends java.lang.Object
    Some Logging Utilities
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String AL_LOG_DIR_PREFIX
      Assembly Line log directory prefix
      static java.lang.String ROOT_LOG_DIR
      Root log directory
    • Constructor Summary

      Constructors 
      Constructor Description
      LogUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String cleanALLogs​(java.lang.String aConfigId, java.lang.String aALName, java.lang.String[] logsToBeDeleted)
      Deletes all the logs which are specified in " logsToBeDeleted" array.
      static void cleanAllOldALLogs​(int aKeepNum)
      Cleans all AL logs and leaves only aKeepNum of them
      static void cleanAllOldALLogs​(java.util.Date aMinDate)
      Cleans all AL logs created after the given Date
      static void cleanAllOldLogs​(int aKeepNum)
      Cleans all logs(AL and EH) and leaves only aKeepNum of them
      static void cleanAllOldLogs​(java.util.Date aMinDate)
      Cleans all logs(AL and EH) created after the given Date
      static java.lang.Boolean cleanOldALLogs​(java.lang.String aConfigId, java.lang.String aALName, int aKeepNum)
      Cleans AL logs, for a given config ID and Assembly Line name, and leaves only aKeepNum of them
      static java.lang.Boolean cleanOldALLogs​(java.lang.String aConfigId, java.lang.String aALName, java.util.Date aMinDate)
      Cleans AL logs, for a given config ID and Assembly Line name, created after the given Date
      static java.lang.Boolean cleanOldALLogs​(java.lang.String aConfigId, java.lang.String aALName, java.util.Date aMinDate, java.util.Date aMaxDate)
      Cleans AL logs, for a given config ID and Assembly Line name, created after the given Date
      static java.lang.String getALLastLogFileName​(java.lang.String aConfigId, java.lang.String aALName)
      Retrieves the available log names, sorts them in ascending order according to the Natural Ordering and returns the last one.
      static java.lang.String getALLog​(java.lang.String aConfigId, java.lang.String aALName, java.lang.String aLogFileName)
      Retrieves the content of the AL log.
      static java.lang.String[] getALLogFileNames​(java.lang.String aConfigId, java.lang.String aALName)
      Retrieves the available component's log files names.
      static java.lang.String[] getALLogFileNames​(java.lang.String aConfigId, java.lang.String aALName, int iNumber)
      Retrieves the specified number of available component's log files names.
      static java.lang.String[] getALLogFileNames​(java.lang.String aConfigId, java.lang.String aALName, java.util.Date dDate)
      Retrieves the available component's log files names after the specified date.
      static java.lang.String[] getALLogFileNames​(java.lang.String aConfigId, java.lang.String aALName, java.util.Date startDate, java.util.Date endDate)
      Retrieves the available component's log files names after the specified date.
      static java.lang.String getALLogLastChunk​(java.lang.String aConfigId, java.lang.String aALName, java.lang.String aLogFileName, int aKilobytes)
      This method retrieves the specified number of kylobytes from the content of a AL's log file as String.
      static java.lang.String[] getAvailableComponentLogFiles​(java.lang.String aComponentTypeDir, java.lang.String aConfigId, java.lang.String aComponentName)
      Retrieves the available component's log files in ascending order.
      static java.lang.String[] getAvailableComponentLogFiles​(java.lang.String aComponentTypeDir, java.lang.String aConfigId, java.lang.String aComponentName, int number)
      Retrieves the specified number of available component's log files sorted in ascending order.
      static java.lang.String[] getAvailableComponentLogFiles​(java.lang.String aComponentTypeDir, java.lang.String aConfigId, java.lang.String aComponentName, java.util.Date dDate)
      Retrieves the available component's log files after the specified date sorted in ascending order.
      static java.lang.String getCleanConfigId​(java.lang.String aConfigId)
      Replaces '/', ':', '\\', '*', '?', '"', '<', '>', '|' symbols with '_' from the given config id
      static java.lang.String getComponentLog​(java.lang.String aLogFileName)
      Retrieves the content of the log file.
      static java.lang.String getComponentLogLastChunk​(java.lang.String aLogFileName, int aKilobytes)
      Retrieves the specified number of kilobytes from the end of the log file.
      static SystemLogAppender getSystemLogAppender​(Log aLog)
      Searches the given Log object for the System Log Appender
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ROOT_LOG_DIR

        public static final java.lang.String ROOT_LOG_DIR
        Root log directory
        See Also:
        Constant Field Values
      • AL_LOG_DIR_PREFIX

        public static final java.lang.String AL_LOG_DIR_PREFIX
        Assembly Line log directory prefix
        See Also:
        Constant Field Values
    • Constructor Detail

      • LogUtils

        public LogUtils()
    • Method Detail

      • getSystemLogAppender

        public static SystemLogAppender getSystemLogAppender​(Log aLog)
        Searches the given Log object for the System Log Appender
        Parameters:
        aLog -
        Returns:
        the System Log Appender, part of the given Log object, null if not found
      • getComponentLog

        public static java.lang.String getComponentLog​(java.lang.String aLogFileName)
                                                throws DIException
        Retrieves the content of the log file.
        Parameters:
        aLogFileName - name of log file.
        Returns:
        the content of the aLogFileName log file as a String
        Throws:
        DIException - if an error occurs
      • getComponentLogLastChunk

        public static java.lang.String getComponentLogLastChunk​(java.lang.String aLogFileName,
                                                                int aKilobytes)
                                                         throws DIException
        Retrieves the specified number of kilobytes from the end of the log file.
        Parameters:
        aLogFileName - name of the file
        aKilobytes - number of kilobytes
        Returns:
        the last aKilobytes of the content of aLogFileName log file as a String
        Throws:
        DIException
      • getALLogFileNames

        public static java.lang.String[] getALLogFileNames​(java.lang.String aConfigId,
                                                           java.lang.String aALName)
                                                    throws DIException
        Retrieves the available component's log files names.
        Parameters:
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aALName - the Assembly Line name
        Returns:
        a String array containing all the available log files for the components in the given Assembly Line
        Throws:
        DIException - if an error occurs.
      • getALLogFileNames

        public static java.lang.String[] getALLogFileNames​(java.lang.String aConfigId,
                                                           java.lang.String aALName,
                                                           int iNumber)
                                                    throws DIException
        Retrieves the specified number of available component's log files names.
        Parameters:
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aALName - the Assembly Line name
        iNumber - how many of the available log files you need
        Returns:
        a String array containing containing the first number amount of the sorted by names according to the natural ordering available log files for the components in the given Assembly Line
        Throws:
        DIException - if an error occurs.
      • getALLogFileNames

        public static java.lang.String[] getALLogFileNames​(java.lang.String aConfigId,
                                                           java.lang.String aALName,
                                                           java.util.Date dDate)
                                                    throws DIException
        Retrieves the available component's log files names after the specified date.
        Parameters:
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aALName - the Assembly Line name
        dDate - the earliest Date for the logs needed
        Returns:
        a String array containing available log files for the components in the given Assembly Line which are created after the given Date
        Throws:
        DIException - if an error occurs.
      • getALLogFileNames

        public static java.lang.String[] getALLogFileNames​(java.lang.String aConfigId,
                                                           java.lang.String aALName,
                                                           java.util.Date startDate,
                                                           java.util.Date endDate)
                                                    throws DIException
        Retrieves the available component's log files names after the specified date.
        Parameters:
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aALName - the Assembly Line name
        startDate - the start Date for the logs needed
        endDate - the end Date for the logs needed
        Returns:
        a String array containing available log files for the components in the given Assembly Line which are created after the given Date
        Throws:
        DIException - if an error occurs.
      • getALLastLogFileName

        public static java.lang.String getALLastLogFileName​(java.lang.String aConfigId,
                                                            java.lang.String aALName)
                                                     throws DIException
        Retrieves the available log names, sorts them in ascending order according to the Natural Ordering and returns the last one.
        Parameters:
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aALName - the Assembly Line name
        Returns:
        The last log according to the Natural Ordering of the names
        Throws:
        DIException
      • getALLog

        public static java.lang.String getALLog​(java.lang.String aConfigId,
                                                java.lang.String aALName,
                                                java.lang.String aLogFileName)
                                         throws DIException
        Retrieves the content of the AL log.
        Parameters:
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aALName - the Assembly Line name
        aLogFileName - the name of the log file
        Returns:
        The content of the Assembly Line log file as String
        Throws:
        DIException - if an error occurs.
      • getALLogLastChunk

        public static java.lang.String getALLogLastChunk​(java.lang.String aConfigId,
                                                         java.lang.String aALName,
                                                         java.lang.String aLogFileName,
                                                         int aKilobytes)
                                                  throws DIException
        This method retrieves the specified number of kylobytes from the content of a AL's log file as String.
        Parameters:
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aALName - the Assembly Line name
        aLogFileName - the name of the log file
        aKilobytes - number of kilobytes.
        Returns:
        The last aKilobytes from the content of the Assembly Line log file as String
        Throws:
        DIException
      • getAvailableComponentLogFiles

        public static java.lang.String[] getAvailableComponentLogFiles​(java.lang.String aComponentTypeDir,
                                                                       java.lang.String aConfigId,
                                                                       java.lang.String aComponentName)
        Retrieves the available component's log files in ascending order.
        Parameters:
        aComponentTypeDir - the component type directory
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aComponentName - the component name
        Returns:
        a String array containing the sorted into ascending order according to the natural ordering of the names of the available log files for the given component
      • getCleanConfigId

        public static java.lang.String getCleanConfigId​(java.lang.String aConfigId)
        Replaces '/', ':', '\\', '*', '?', '"', '<', '>', '|' symbols with '_' from the given config id
        Parameters:
        aConfigId - configuration ID
        Returns:
        the modified config name.
      • cleanAllOldLogs

        public static void cleanAllOldLogs​(java.util.Date aMinDate)
                                    throws DIException
        Cleans all logs(AL and EH) created after the given Date
        Parameters:
        aMinDate - after this date , the log are deleted
        Throws:
        DIException - if an error occurs.
      • cleanAllOldLogs

        public static void cleanAllOldLogs​(int aKeepNum)
                                    throws DIException
        Cleans all logs(AL and EH) and leaves only aKeepNum of them
        Parameters:
        aKeepNum - number of logs to keep.
        Throws:
        DIException - if an error occurs.
      • cleanAllOldALLogs

        public static void cleanAllOldALLogs​(java.util.Date aMinDate)
                                      throws DIException
        Cleans all AL logs created after the given Date
        Parameters:
        aMinDate - after this date , the log are deleted
        Throws:
        DIException - if an error occurs.
      • cleanAllOldALLogs

        public static void cleanAllOldALLogs​(int aKeepNum)
                                      throws DIException
        Cleans all AL logs and leaves only aKeepNum of them
        Parameters:
        aKeepNum - number of logs to keep
        Throws:
        DIException - if an error occurs
      • cleanOldALLogs

        public static java.lang.Boolean cleanOldALLogs​(java.lang.String aConfigId,
                                                       java.lang.String aALName,
                                                       java.util.Date aMinDate)
                                                throws DIException
        Cleans AL logs, for a given config ID and Assembly Line name, created after the given Date
        Parameters:
        aConfigId - configuration ID
        aALName - name of the assembly line
        aMinDate - after this date , the log are deleted
        Returns:
        whether the operation was successful
        Throws:
        DIException
      • cleanOldALLogs

        public static java.lang.Boolean cleanOldALLogs​(java.lang.String aConfigId,
                                                       java.lang.String aALName,
                                                       java.util.Date aMinDate,
                                                       java.util.Date aMaxDate)
                                                throws DIException
        Cleans AL logs, for a given config ID and Assembly Line name, created after the given Date
        Parameters:
        aConfigId - configuration ID
        aALName - name of the assembly line
        aMinDate - after this date , the log are deleted
        aMaxDate - before this date , the log are deleted
        Returns:
        whether the operation was successful
        Throws:
        DIException
      • cleanOldALLogs

        public static java.lang.Boolean cleanOldALLogs​(java.lang.String aConfigId,
                                                       java.lang.String aALName,
                                                       int aKeepNum)
                                                throws DIException
        Cleans AL logs, for a given config ID and Assembly Line name, and leaves only aKeepNum of them
        Parameters:
        aConfigId - configuration ID
        aALName - name of the assembly line
        aKeepNum - number of logs to keep
        Returns:
        whether the operation was successful
        Throws:
        DIException
      • cleanALLogs

        public static java.lang.String cleanALLogs​(java.lang.String aConfigId,
                                                   java.lang.String aALName,
                                                   java.lang.String[] logsToBeDeleted)
                                            throws DIException
        Deletes all the logs which are specified in " logsToBeDeleted" array.
        Parameters:
        aConfigId - identification of the AssemblyLine's Config Instance.
        aALName - the name of the AssemblyLine whose logs will be cleaned up.
        logsToBeDeleted - name of the log files which are to be deleted.
        Returns:
        a String that holds null if the log files are deleted successfully; else comma separated names of the log files which are not deleted.
        Throws:
        DIException - if an error occurs while deleting log files.
      • getAvailableComponentLogFiles

        public static java.lang.String[] getAvailableComponentLogFiles​(java.lang.String aComponentTypeDir,
                                                                       java.lang.String aConfigId,
                                                                       java.lang.String aComponentName,
                                                                       int number)
        Retrieves the specified number of available component's log files sorted in ascending order.
        Parameters:
        aComponentTypeDir - the component type directory
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aComponentName - the component name
        number - how many of the available log files you need
        Returns:
        a String array containing the first number amount of the sorted into ascending order according to the natural ordering of the names of the available log files for the given component
      • getAvailableComponentLogFiles

        public static java.lang.String[] getAvailableComponentLogFiles​(java.lang.String aComponentTypeDir,
                                                                       java.lang.String aConfigId,
                                                                       java.lang.String aComponentName,
                                                                       java.util.Date dDate)
        Retrieves the available component's log files after the specified date sorted in ascending order.
        Parameters:
        aComponentTypeDir - the component type directory
        aConfigId - the ID of the configuration the Assembly Line belongs to
        aComponentName - the component name
        dDate - the earliest Date for the logs needed
        Returns:
        a String array containing available log files for the given component which are created after the given Date, sorted into ascending order according to the natural ordering of their names