Class RotateStrategyBySize

  • All Implemented Interfaces:
    RotateStrategy

    public class RotateStrategyBySize
    extends java.lang.Object
    implements RotateStrategy
    Rotation strategy based on size written to log file. The strategy will signal that a rotation is needed if the size goes above a set limit. Due to performance reasons the limit is not strictly enforced, however, the strategy has at most an error of the longest single data message written to the logging system. The error will occur immediately after a rotation, when the strategy is reset and the data that triggered the rotation is written. The strategy's internal counter will then be off with data.length() bytes.
    Author:
    Leo Sutic, Bernhard Huber
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long m_currentSize  
      private long m_maxSize  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isRotationNeeded​(java.lang.String data, java.io.File file)
      Check if now a log rotation is neccessary.
      void reset()
      Reset log size written so far.
      • Methods inherited from class java.lang.Object

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

      • m_maxSize

        private long m_maxSize
      • m_currentSize

        private long m_currentSize
    • Constructor Detail

      • RotateStrategyBySize

        public RotateStrategyBySize()
        Rotate logs by size. By default do log rotation before writing approx. 1MB of messages
      • RotateStrategyBySize

        public RotateStrategyBySize​(long maxSize)
        Rotate logs by size.
        Parameters:
        maxSize - rotate before writing maxSize [byte] of messages
    • Method Detail

      • reset

        public void reset()
        Reset log size written so far.
        Specified by:
        reset in interface RotateStrategy
      • isRotationNeeded

        public boolean isRotationNeeded​(java.lang.String data,
                                        java.io.File file)
        Check if now a log rotation is neccessary.
        Specified by:
        isRotationNeeded in interface RotateStrategy
        Parameters:
        data - the message about to be written to the log system
        file - not used
        Returns:
        boolean return true if log rotation is neccessary, else false