Class LogUtil

java.lang.Object
com.reallifedeveloper.common.domain.LogUtil

public class LogUtil extends Object
A utility class to simplify working with logs.
Author:
RealLifeDeveloper
  • Constructor Details

    • LogUtil

      public LogUtil()
  • Method Details

    • removeCRLF

      public static String removeCRLF(String s)
      Removes all occurrences of carriage return (\r) and linefeed (\n) from a string.

      This is useful when logging something that originates from a user, in order to avoid CRLF injection. See https://www.invicti.com/learn/crlf-injection/.

      The method is null-safe and returns null if the input string is null.

      Parameters:
      s - the string from which to remove CRLF
      Returns:
      s with all occurrences of CR and LF removed
    • removeCRLF

      public static String removeCRLF(Object o)
      Given a non-null object, calls the toString method on the object and returns the result of calling removeCRLF(String) on the string representation of the object.

      For null simply returns null.

      Parameters:
      o - the object for which to remove CRLF from its string representation
      Returns:
      o.toString() with all occurrences of CR and LF removed, or null if o is null