Package com.helger.commons.log
Class InMemoryLogger
- java.lang.Object
-
- com.helger.commons.log.InMemoryLogger
-
- All Implemented Interfaces:
ICommonsIterable<LogMessage>,IHasErrorLevels<LogMessage>,IHasSize,IClearable,Iterable<LogMessage>
@NotThreadSafe public class InMemoryLogger extends Object implements IHasErrorLevels<LogMessage>, IHasSize, IClearable
Keeps a set ofLogMessageobjects in memory, offering an API similar to SLF4J.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description InMemoryLogger()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected LogMessagecreateLogMessage(IErrorLevel eErrorLevel, Serializable aMsg, Throwable t)Override this method to create a different LogMessage object or to filter certain log messages.voiderror(Serializable aMsg)voiderror(Serializable aMsg, Throwable t)ICommonsList<LogMessage>getAllMessages()voidinfo(Serializable aMsg)voidinfo(Serializable aMsg, Throwable t)booleanisEmpty()Iterator<LogMessage>iterator()voidlog(IErrorLevel eErrorLevel, Serializable aMsg)voidlog(IErrorLevel eErrorLevel, Serializable aMsg, Throwable t)protected voidonAddLogMessage(LogMessage aLogMessage)Callback method that is invoked after a message was added.EChangeremoveAll()Reset the contents of the element to the after-construction state.intsize()voidsuccess(Serializable aMsg)voidsuccess(Serializable aMsg, Throwable t)StringtoString()voidwarn(Serializable aMsg)voidwarn(Serializable aMsg, Throwable t)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsIterable
containsAny, containsNone, containsOnly, findAll, findAllInstanceOf, findAllMapped, findAllMapped, findAllMapped, findFirst, findFirst, findFirstIndex, findFirstMapped, findFirstMapped, findLastIndex, forEachBreakable, forEachByIndex, forEachThrowing, getCount, getCount
-
Methods inherited from interface com.helger.commons.error.level.IHasErrorLevels
containsAtLeastOneError, containsAtLeastOneFailure, containsAtLeastOneSuccess, containsAtLeastOneWarningOrError, containsNoError, containsNoFailure, containsNoSuccess, containsOnlyError, containsOnlyFailure, containsOnlySuccess, getErrorCount, getFailureCount, getMostSevereErrorLevel, getSuccessCount
-
Methods inherited from interface com.helger.commons.lang.IHasSize
isNotEmpty
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
createLogMessage
@Nullable @OverrideOnDemand protected LogMessage createLogMessage(@Nonnull IErrorLevel eErrorLevel, @Nonnull Serializable aMsg, @Nullable Throwable t)
Override this method to create a different LogMessage object or to filter certain log messages.- Parameters:
eErrorLevel- Error level. Nevernull.aMsg- The message object. Nevernull.t- An optional exception. May benull.- Returns:
- The returned value. May be
nullin which case the message will not be logged.
-
onAddLogMessage
@OverrideOnDemand protected void onAddLogMessage(@Nonnull LogMessage aLogMessage)
Callback method that is invoked after a message was added.- Parameters:
aLogMessage- The added log message. Nevernull.
-
log
public void log(@Nonnull IErrorLevel eErrorLevel, @Nonnull Serializable aMsg)
-
log
public void log(@Nonnull IErrorLevel eErrorLevel, @Nonnull Serializable aMsg, @Nullable Throwable t)
-
error
public void error(@Nonnull Serializable aMsg)
-
error
public void error(@Nonnull Serializable aMsg, @Nullable Throwable t)
-
warn
public void warn(@Nonnull Serializable aMsg)
-
warn
public void warn(@Nonnull Serializable aMsg, @Nullable Throwable t)
-
info
public void info(@Nonnull Serializable aMsg)
-
info
public void info(@Nonnull Serializable aMsg, @Nullable Throwable t)
-
success
public void success(@Nonnull Serializable aMsg)
-
success
public void success(@Nonnull Serializable aMsg, @Nullable Throwable t)
-
getAllMessages
@Nonnull @ReturnsMutableCopy public ICommonsList<LogMessage> getAllMessages()
-
iterator
@Nonnull public Iterator<LogMessage> iterator()
- Specified by:
iteratorin interfaceIterable<LogMessage>
-
size
@Nonnegative public int size()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceIHasSize- Returns:
trueif no items are present,falseif at least a single item is present.- See Also:
IHasSize.size(),IHasSize.isNotEmpty()
-
removeAll
@Nonnull public EChange removeAll()
Description copied from interface:IClearableReset the contents of the element to the after-construction state.- Specified by:
removeAllin interfaceIClearable- Returns:
EChange.CHANGEDif at least one element was cleared,EChange.UNCHANGEDotherwise.
-
-