Package de.stefanfrings.utils
Class ObjectLogger
java.lang.Object
de.stefanfrings.utils.ObjectLogger
Print the content of any object to human readable String.
Examples how to get the content of object o:
- String s=new ObjectLogger(o).toString();
- String s=new ObjectLogger().toString(o);
- String s=new ObjectLogger().addFieldNamesToHideValue("keycode").toString(o);
- log.debug("Processing {}", new ObjectLogger(o));
The default settings are:
- maximum nesting dept of classes: 10
- maximum number of elements in arrays and containers: 10
- maximum total character: 16000 (this is not a hard limit, the actual result my be a little larger)
- maximum size of strings: 80
- hide values of: password
- hide totally: serialVersionUID, log and logger
- fields with value=null are skipped
- Author:
- Stefan Frings, http://stefanfrings.de/javautils
-
Constructor Summary
ConstructorsConstructorDescriptionCall this constructor, then optionally call some setters to configure behaviour, then toString(o) which generates the output.Call this constructor, then optionally call some setters to configure behaviour, then toString() which generates the output. -
Method Summary
Modifier and TypeMethodDescriptionaddFieldNamesToHideTotally
(String... fieldNames) Add field names which shall be hidden totally.addFieldNamesToHideTotally
(Collection<String> fieldNames) Add field names which shall be hidden totally.addFieldNamesToHideValue
(String... fieldNames) Add field names whose values shall be hidden.addFieldNamesToHideValue
(Collection<String> fieldNames) Add field names whose values shall be hidden.setMaxListSize
(int maxListSize) Set the maximum number of elements in arrays and lists.setMaxNestingDepth
(int maxNestingDepth) Set the maximum nesting depth of sub-objects.setMaxStringSize
(int maxStringSize) Set the maximum number of characters per StringsetMaxTotalCharacters
(int maxTotalCharacters) Set the maximum number of characters in the result.setShowNull
(boolean showNull) Configure whether fields with value null shall appear in the output.toString()
Returns the content of the object which was passed to the construtor as human readable string.Returns the content of the object as human readable string.
-
Constructor Details
-
ObjectLogger
public ObjectLogger()Call this constructor, then optionally call some setters to configure behaviour, then toString(o) which generates the output. -
ObjectLogger
Call this constructor, then optionally call some setters to configure behaviour, then toString() which generates the output.- Parameters:
o
- The object to log
-
-
Method Details
-
setMaxNestingDepth
Set the maximum nesting depth of sub-objects.- Parameters:
maxNestingDepth
- Maximum nesting depth of sub-objects.- Returns:
- A reference to this object.
-
setMaxListSize
Set the maximum number of elements in arrays and lists.- Parameters:
maxListSize
- Maximum number of elements in arrays and lists.- Returns:
- A reference to this object.
-
setMaxTotalCharacters
Set the maximum number of characters in the result.- Parameters:
maxTotalCharacters
- Maximum number of characters in the result.- Returns:
- A reference to this object.
-
setMaxStringSize
Set the maximum number of characters per String- Parameters:
maxStringSize
- Maximum number of characters per String- Returns:
- A reference to this object.
-
setShowNull
Configure whether fields with value null shall appear in the output.- Parameters:
showNull
- Boolean flag, true enables the output.- Returns:
- A reference to this object.
-
addFieldNamesToHideValue
Add field names whose values shall be hidden.- Parameters:
fieldNames
- Maximum number of characters per String- Returns:
- A reference to this object.
-
addFieldNamesToHideValue
Add field names whose values shall be hidden.- Parameters:
fieldNames
- Maximum number of characters per String- Returns:
- A reference to this object.
-
addFieldNamesToHideTotally
Add field names which shall be hidden totally.- Parameters:
fieldNames
- Maximum number of characters per String- Returns:
- A reference to this object.
-
addFieldNamesToHideTotally
Add field names which shall be hidden totally.- Parameters:
fieldNames
- Maximum number of characters per String- Returns:
- A reference to this object.
-
toString
Returns the content of the object as human readable string.- Parameters:
o
- The object to convert.- Returns:
- The human readable String representation of the object.
-
toString
Returns the content of the object which was passed to the construtor as human readable string.
-