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 @Nullable StringremoveCRLF(@Nullable Object o) Given a non-null object, calls thetoStringmethod on the object and returns the result of callingremoveCRLF(String)on the string representation of the object.static @Nullable StringremoveCRLF(@Nullable 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
nullif the input string isnull.- Parameters:
s- the string from which to remove CRLF- Returns:
swith all occurrences of CR and LF removed
-
removeCRLF
Given a non-null object, calls thetoStringmethod on the object and returns the result of callingremoveCRLF(String)on the string representation of the object.For
nullsimply 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, ornullifoisnull
-