java.lang.Object
org.autogui.base.log.GuiLogManager
- Direct Known Subclasses:
GuiLogManagerConsole
,GuiSwingLogManager
the base class for log managers
GuiLogManager.get().log("hello");
GuiLogManager.get().logFormat("%d", 123);
try { ... } catch (Exception ex) { GuiLogManager.get().logError(ex); }
try (GuiLogEntryProgress p = GuiLogManager.get().logProgress()) { //see logProgress()
...
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
a stream wrapper with writing to a log-manager, used byGuiLogManager.LogPrintStream
static class
a console-wrapper stream, with supporting printing exceptionsstatic enum
static class
a default handler for integrating the log-manager -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionformatDuration
(Instant from, Instant to) formatMessageLine
(String msg) static GuiLogManager
get()
getErr()
boolean
isSymbol
(char c) create and report a log entry.create an exception entry and show itcreate and report a log entry.create an active progress entry and show it.logProgress
(int max) create a string entry and show it.create a string entry and show it.void
replaceConsole
(boolean replaceError, boolean replaceOutput) replaceSystem.err
andSystem.out
with a string redirecting to this manager.void
replace the default uncaught handler withGuiLogManager.LogUncaughtHandler
by callingThread.setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler)
.void
resetErr()
synchronized withSystem.class
void
resetOut()
synchronized withSystem.class
void
synchronized withSystem.class
static void
setManager
(GuiLogManager manager) void
show
(GuiLogEntry entry) update display of the entry.void
-
Field Details
-
manager
-
-
Constructor Details
-
GuiLogManager
public GuiLogManager()
-
-
Method Details
-
get
- Returns:
- a shared instance
-
setManager
-
log
create and report a log entry. args are concatenated with a space and pass tologString(String)
. if the previous arg is a String, and it ends with an ASCII symbol char, it will not insert a space.log("hello", "world") => logString("hello world") log("hello:", "world") => logString("hello:world") log("x=", 1, "y=", 2, "ex", new Exception()) => logString("x=1 y=2 ex") and logError(new Exception())
when the last item of args is an exception, it will be passed tologError(Throwable)
. if the args is only a single exception, it will return itsGuiLogEntryException
, otherwiseGuiLogEntryString
- Parameters:
args
- concatenated values for creating a log entry.- Returns:
- the created log entry
-
isSymbol
public boolean isSymbol(char c) -
logFormat
create and report a log entry. useString.format(String, Object...)
and pass tologString(String)
- Parameters:
format
- the format stringargs
- the arguments for the format- Returns:
- the created log entry
-
replaceConsole
public void replaceConsole(boolean replaceError, boolean replaceOutput) replaceSystem.err
andSystem.out
with a string redirecting to this manager. System.err will be completely replaced with the manager, because the manager usually outputs an entry to the original System.err. System.out will be replaced with a manager stream with original System.out. those replaced streams are instances ofGuiLogManager.LogPrintStream
.synchronized with
System.class
- Parameters:
replaceError
- if true, it will replace with a newGuiLogManager.LogPrintStream
.replaceOutput
- if true, it will replace with a newGuiLogManager.LogPrintStream
.
-
resetErr
public void resetErr()synchronized withSystem.class
- Since:
- 1.1
-
resetOut
public void resetOut()synchronized withSystem.class
- Since:
- 1.1
-
replaceUncaughtHandler
public void replaceUncaughtHandler()replace the default uncaught handler withGuiLogManager.LogUncaughtHandler
by callingThread.setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler)
. this makes the uncaught exception will be sent to the manager.synchronized with
System.class
-
resetUncaughtHandler
public void resetUncaughtHandler()synchronized withSystem.class
- Since:
- 1.1
-
getSystemErr
- Returns:
- obtains the original
System.err
from wrappedSystem.err
-
getErr
-
logString
create a string entry and show it. calllogString(String, boolean)
with fromStdout=false- Parameters:
str
- the string for the entry- Returns:
- the created log entry
-
logString
create a string entry and show it.- Parameters:
str
- the string for the entryfromStandard
- whether the string come from the standard output (or error) redirection- Returns:
- the created log entry
- Since:
- 1.1
-
formatTime
- Parameters:
i
- the formatted date-time- Returns:
[YYYY-mm-dd HH:MM:SS.LLL]
with local date-time
-
logError
create an exception entry and show it- Parameters:
ex
- the exception- Returns:
- the created entry
-
logProgress
create an active progress entry and show it. the returned progress is determinate (isIndeterminate() == false), and notifies progress changes to the manager byupdateProgress(GuiLogEntryProgress)
try (GuiLogEntryProgress p = manager.logProgress();) { for (...) { //those methods will cause a runtime-exception if the thread is interrupted. p.addValueP(0.01f) .setMessage("running ..."); ... //the running code can checks interruption if (Thread.interrupted()) { break; } ... } } catch (Exception ex) { ... }
- Returns:
- the created progress entry
-
logProgress
- Parameters:
max
- a maximum value- Returns:
- an active progress entry with the maximum value, and show it.
-
updateProgress
-
show
update display of the entry.- Parameters:
entry
- the displayed entry
-
formatMessageLine
- Parameters:
msg
- the message to be formatted- Returns:
- the formatted line: a tab and a newline are converted to a space. the length is limited to 70 chars
-
formatDuration
- Parameters:
from
- the start timeto
- the end time- Returns:
[[[[[[<years>y] <months>mo] <days>d] <hours>h] <minutes>m] <seconds>s] (<millis>ms|<nanos>ns)
: years, months, and days are calculated by local date
-