Class SyncLogger
synchronizer implementations
.
It prepends the specified messages with the following information:
- name of the synchronizer taken from its configuration in the set up in the <structure-synchronizer> module (see
SynchronizerDescriptor.getLabel()
, - mode of synchronization (one-time synchronization, periodical autosync, or resync),
- name and ID of the structure being synchronized,
- ID of the
synchronizer instance
.
Name of the user under which the synchronization is run is not provided, as it is automatically inserted into the log message by JIRA.
Features
There is a bunch of helper methods to pretty-print the user under which the synchronizer runs (username()
),
produce warnings about typical StructureExceptions
that may be encountered by synchronizers (warnStructureException(StructureException)
),
and select messages based on the synchronization mode (selectBySyncMode(Object, Object, Object)
).
All logging methods that take Object...
vararg parameter delimit its contents putting a single space before the parameter. If the parameter is a character or a single-character String
that is a punctuation mark, the space is not inserted before the parameter. If the parameter is an Object[]
, its contents are added to the output as if they belonged to the original Object...
parameter.
Example:
SyncLogger log = ... ; log.warn("cannot run because of", isKaboozle() ? "kaboozle" : new Object[]{"grumbles with error", getError()}, ':', getCause())
will produce the following log message:
<synchronizer label> autosync #239 for structure 'Unresolved in 2.0' (#156) cannot run because of grumbles with error FATAL: something went wrong
Methods that end with exceptionIfDebug
attempt to log exception stack trace if log level is DEBUG or lower and print only exception message if log level is higher.
- Since:
- 7.2.0 (Structure 2.0)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSyncLogger
(Logger logger, SyncInstance sync, StructureManager structureManager, RowManager rowManager, boolean auto) -
Method Summary
Modifier and TypeMethodDescriptionappendForest
(Forest forest, StringBuilder sb) appendIssue
(Long issueId, StringBuilder sb) Adds debug information about an issue by ID.appendItem
(long rowId, StringBuilder sb) appendItem
(ItemIdentity itemId, StringBuilder sb) appendItemForest
(ItemForest itemForest, StringBuilder sb) appendRows
(LongIterable rowIds, StringBuilder sb) createLogMessage
(Object... msgs) void
void
debugException
(Throwable ex, Object... msgs) final String
void
void
errorException
(Throwable e, Object... msgs) static SyncLogger
get()
Retrieves SyncLogger from the thread-local storage.Logger
void
void
infoException
(Throwable e, Object... msgs) boolean
static boolean
isDebug()
boolean
static boolean
isInfo()
boolean
boolean
issue
(Issue issue) Retrieves debug information about an issue by ID.issues
(LongIterable issues) itemForest
(ItemForest itemForest) void
void
pushPrefix
(String prefixToAppend) row
(long rowId) rows
(LongIterable rowIds) selectBySyncMode
(Object ifAuto, Object ifResync, Object ifOneTime) static void
set
(SyncLogger syncLog) This is internal method that is used by the synchronization subsystem.void
setLogger
(Logger logger) void
structure
(long structureId) username()
void
void
warnException
(Throwable ex, Object... msgs) void
warnExceptionIfDebug
(Throwable ex, Object... msgs) Contains standard error descriptions for common StructureExceptions
-
Constructor Details
-
SyncLogger
public SyncLogger(Logger logger, @Nullable SyncInstance sync, StructureManager structureManager, RowManager rowManager, boolean auto)
-
-
Method Details
-
get
Retrieves SyncLogger from the thread-local storage. Must only be called during synchronization; if called at any other time, throws an
UnsupportedOperationException
.The returned SyncLogger delegates to
Logger
for the currentStructureSynchronizer
class. -
set
This is internal method that is used by the synchronization subsystem. Do not use this method. Call from threads other than the synchronization thread will result inUnsupportedOperationException
being thrown. -
isInfo
public static boolean isInfo() -
isDebug
public static boolean isDebug() -
getPrefix
-
setPrefix
-
pushPrefix
-
popPrefix
public void popPrefix() -
getLogger
public Logger getLogger() -
setLogger
public void setLogger(Logger logger) -
isOneTimeSync
public boolean isOneTimeSync() -
isAutoSync
public boolean isAutoSync() -
info
-
infoException
-
debug
-
debugException
-
warn
-
warnException
-
warnExceptionIfDebug
-
error
-
errorException
-
isInfoEnabled
public boolean isInfoEnabled() -
isDebugEnabled
public boolean isDebugEnabled() -
createLogMessage
-
defaultPrefix
-
username
-
issue
Retrieves debug information about an issue by ID. Costly method. -
appendIssue
Adds debug information about an issue by ID. Costly method. -
issue
-
issues
-
issues
-
structure
-
selectBySyncMode
-
appendForest
-
forest
-
appendItemForest
-
itemForest
-
appendRows
-
appendItem
-
appendItem
-
row
-
rows
-
warnStructureException
Contains standard error descriptions for common StructureExceptions- Returns:
- a specific string if the exception represents a common known case, null otherwise (generic message should be used)
-