Class LogUtil
java.lang.Object
com.reallifedeveloper.common.domain.LogUtil
A utility class to simplify working with logs.
- Author:
- RealLifeDeveloper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
removeCRLF
(Object o) Given a non-null object, calls thetoString
method on the object and returns the result of callingremoveCRLF(String)
on the string representation of the object.static String
removeCRLF
(String s) Removes all occurrences of carriage return (\r
) and linefeed (\n
) from a string.
-
Constructor Details
-
LogUtil
public LogUtil()
-
-
Method Details
-
removeCRLF
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 isnull
.- Parameters:
s
- the string from which to remove CRLF- Returns:
s
with all occurrences of CR and LF removed
-
removeCRLF
Given a non-null object, calls thetoString
method on the object and returns the result of callingremoveCRLF(String)
on the string representation of the object.For
null
simply returnsnull
.- Parameters:
o
- the object for which to remove CRLF from its string representation- Returns:
o.toString()
with all occurrences of CR and LF removed, ornull
ifo
isnull
-