public class MainCmdLoggingStream extends java.lang.Object implements MainCmdLogging_ifc
MainCmd class,
but independent of that. It is intent to use if the logging features are other than in the
main routine given, or if MainCmd is not used for the originally invocation of a Java program.
Especially it can be used for logging output inside a JZtxtcmdExecuter for some
special routines.| Modifier and Type | Field and Description |
|---|---|
protected java.lang.Appendable |
app |
private java.text.SimpleDateFormat |
dateFormat |
protected java.io.OutputStream |
out
Stream to output all logging information.
|
private java.io.PrintStream |
printStream
Created on demand.
|
private java.io.PrintWriter |
printWriter
Created on demand.
|
(package private) int |
reportLevel
This variable determines which level is output.
|
private static java.lang.String |
sLeft |
static java.lang.String |
sVersion
Version, history and license.
|
private java.lang.StringBuilder |
u |
anytime, eventOrder, exitSuccessfull, exitUserAbort, exitWithArgumentError, exitWithErrors, exitWithFileProblems, exitWithNotes, exitWithWarnings, fineEventOrder, interested, versiondebug, error, fineDebug, fineInfo, info, minSecondsFormat, mNeverOutputToDisplay, mReportLevel, warning| Constructor and Description |
|---|
MainCmdLoggingStream(java.io.OutputStream out)
Create with given output stream, or empty.
|
MainCmdLoggingStream(java.io.OutputStream out,
int reportLevel)
Create with given output stream, or empty.
|
MainCmdLoggingStream(java.lang.String sDateFormat,
java.lang.Appendable app)
Create with given Appendable and dateformat.
|
MainCmdLoggingStream(java.lang.String sDateFormat,
java.lang.Appendable app,
int reportLevel)
Create with given output stream, or empty.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Appendable |
append(char c) |
java.lang.Appendable |
append(java.lang.CharSequence csq) |
java.lang.Appendable |
append(java.lang.CharSequence csq,
int start,
int end) |
void |
close()
A call of this method closes the devices, which processed the message.
|
void |
flush()
A call of this method causes an activating of transmission of all messages since last flush.
|
void |
flushReport()
Writes the content in the physical medium.
|
int |
getExitErrorLevel()
Returns 0
|
int |
getReportLevel()
access to the level of report.
|
int |
getReportLevelFromIdent(int ident)
gets the associated report level to a report identifier.
|
boolean |
isOnline()
Checks whether the message output is available.
|
void |
openReportfile(java.lang.String sFileReport,
boolean bAppendReport) |
void |
report(java.lang.CharSequence sText,
java.lang.Throwable exception)
report of a excpetion (in a new line)
|
void |
report(int nLevel,
java.lang.CharSequence string)
report inside a line
|
void |
reportln(int nLevel,
java.lang.CharSequence string)
report begins at a new a line
|
void |
reportln(int nLevel,
int nLeftMargin,
java.lang.CharSequence string)
report begins at a new a line with left margin
|
boolean |
sendMsg(int identNumber,
java.lang.CharSequence text,
java.lang.Object... args)
Sends a message.
|
boolean |
sendMsgTime(int identNumber,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
java.lang.Object... args)
Sends a message.
|
boolean |
sendMsgVaList(int identNumber,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
Va_list args)
Sends a message.
|
void |
setExitErrorLevel(int level)
set the exitErrorLevel of the maximum of given level of every call.
|
void |
setOutputChannels(java.lang.Appendable outP,
java.lang.Appendable errP)
Sets destinations for output and error output.
|
int |
setReportLevel(int newLevel)
Set another level inside programming.
|
void |
setReportLevelToIdent(int ident,
int nLevelActive)
Sets a dedicated level number to the known output priorities.
|
(package private) void |
writeBuffer() |
void |
writeError(java.lang.CharSequence sError)
Writes an error line.
|
void |
writeError(java.lang.String msg,
java.lang.Object... args)
Writes a beginning new line with the prepared text to an error output.
|
void |
writeError(java.lang.String sError,
java.lang.Throwable exception)
Writes an error line caused by an exception.
|
void |
writeErrorAdd(java.lang.String msg,
java.lang.Object... args)
Writes an additional information for the error message after the already outputted error line in the same line.
|
void |
writef(java.lang.String msg,
java.lang.Object... args)
Writes the prepared text to the log as information.
|
void |
writeInfo(java.lang.CharSequence sInfo)
Appends an info to the end of the previous info, @see
LogMessage.writeInfoln(CharSequence). |
void |
writeInfo(java.lang.String msg,
java.lang.Object... args)
Writes the prepared text to the log as information.
|
void |
writeInfoAdd(java.lang.String msg,
java.lang.Object... args)
Writes an additional information for the info message after the already output info line in the same line.
|
void |
writeInfoln(java.lang.CharSequence sInfo)
Writes an info line.
|
(package private) void |
writeln(int level,
int nLeftMargin,
java.lang.CharSequence ss) |
void |
writeStackTrace(java.lang.Exception exc) |
void |
writeWarning(java.lang.CharSequence sError)
Writes an error line.
|
void |
writeWarning(java.lang.String msg,
java.lang.Object... args)
Writes a beginning new line with the prepared text to an standard or warning output.
|
void |
writeWarningAdd(java.lang.String msg,
java.lang.Object... args)
Writes an additional information for the warning message after the already outputt warning line in the same line.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmsgSec, timeCurr, timeMsgpublic static final java.lang.String sVersion
MainCmdLogging_ifc and any class which does not have
an association to the MainCmd.
protected java.io.OutputStream out
protected final java.lang.Appendable app
private final java.lang.StringBuilder u
private final java.text.SimpleDateFormat dateFormat
private static java.lang.String sLeft
private java.io.PrintWriter printWriter
private java.io.PrintStream printStream
int reportLevel
LogMessage.fineDebug etc.public MainCmdLoggingStream(java.io.OutputStream out)
out - may be null, use openReportfile(String, boolean) than.public MainCmdLoggingStream(java.io.OutputStream out,
int reportLevel)
out - may be null, use openReportfile(String, boolean) than.public MainCmdLoggingStream(java.lang.String sDateFormat,
java.lang.Appendable app)
sDateFormat - see simpleDateFormatter, use "MMM-dd HH:mm:ss.SSS: " for example.app - may be null, use openReportfile(String, boolean) than.public MainCmdLoggingStream(java.lang.String sDateFormat,
java.lang.Appendable app,
int reportLevel)
sDateFormat - see simpleDateFormatter, use "MMM-dd HH:mm:ss.SSS: " for example.app - may be null, use openReportfile(String, boolean) than.public void flushReport()
LogMessageflushReport in interface LogMessagepublic int getExitErrorLevel()
getExitErrorLevel in interface MainCmdLogging_ifcMainCmdLogging_ifc.getExitErrorLevel()public int getReportLevel()
LogMessagegetReportLevel in interface LogMessagepublic int getReportLevelFromIdent(int ident)
LogMessagegetReportLevelFromIdent in interface LogMessageident - The identifier.public void openReportfile(java.lang.String sFileReport,
boolean bAppendReport)
throws java.io.FileNotFoundException
openReportfile in interface MainCmdLogging_ifcjava.io.FileNotFoundExceptionpublic void report(int nLevel,
java.lang.CharSequence string)
LogMessagereport in interface LogMessagevoid writeBuffer()
void writeln(int level,
int nLeftMargin,
java.lang.CharSequence ss)
public void report(java.lang.CharSequence sText,
java.lang.Throwable exception)
LogMessagereport in interface LogMessagepublic void reportln(int nLevel,
int nLeftMargin,
java.lang.CharSequence string)
LogMessagereportln in interface LogMessagenLevel - write the report only if the demand level is greater or equal.nLeftMargin - determins a left margin. First a new line is outputted, followed by '*' and spaces.string - String to write.public void reportln(int nLevel,
java.lang.CharSequence string)
LogMessagereportln in interface LogMessagenLevel - write the report only if the demand level is greater or equal.string - String to write.public void setExitErrorLevel(int level)
MainCmdLogging_ifcsetExitErrorLevel in interface MainCmdLogging_ifclevel - Errorlevel how defined in Report, 0 is the lowest level (successfull), >0 is worse.public void setOutputChannels(java.lang.Appendable outP,
java.lang.Appendable errP)
MainCmdLogging_ifcsetOutputChannels in interface MainCmdLogging_ifcoutP - Destination for output. If null, current output isn't change.errP - Destination for error output. If null, current output isn't change.public void setReportLevelToIdent(int ident,
int nLevelActive)
LogMessagesetReportLevelToIdent in interface LogMessagenLevelActive - Ones of the known priotity levels Report.error to Report.fineDebug.
class MyModule
{ /**Define module-specific numbers to identify a level.
* The numbers should be define regarding a band of numbers in the application.
* /
static final int myReportLevel1 = 3500, myReportLevel2=3501;
void init()
{ setLevelActive(myReportLevel1, Report.info); //This reports should be outputted always
setLevelActive(myReportLevel2, Report.debug); //This reports are debug infos.
}
void processAnything()
{ report.reportln( myReportLevel1, "InfoText"); //It depends on the report level settings
report.reportln( myReportLevel2, "DebugText");//whether it is outputed or not.
}
public int setReportLevel(int newLevel)
LogMessagesetReportLevel in interface LogMessagepublic void writeError(java.lang.CharSequence sError)
LogMessagewriteError in interface LogMessagesError - The error text, it should be without such hot spot words line "!!!ERROR!!!",
because the distinction in display should be done by the implementation of this method.
A good sample is writeErrorln("cannot create file: " + sFileName);public void writeInfo(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteInfo in interface LogMessagemsg - should begin with "\n", can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public void writef(java.lang.String msg,
java.lang.Object... args)
LogMessagewritef in interface LogMessagemsg - should begin with "\n", can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public void writeInfoAdd(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteInfoAdd in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public void writeWarning(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteWarning in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public void writeWarningAdd(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteWarningAdd in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public void writeError(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteError in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public void writeErrorAdd(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteErrorAdd in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public void writeError(java.lang.String sError,
java.lang.Throwable exception)
LogMessagewriteError in interface LogMessageexception - The catched Exception. The getMessage()-part of the exception is written after sError.
The stacktrace of the exception is written to report.public void writeInfo(java.lang.CharSequence sInfo)
LogMessageLogMessage.writeInfoln(CharSequence).writeInfo in interface LogMessagesInfo - String to be written.public void writeInfoln(java.lang.CharSequence sInfo)
LogMessagewriteInfoln in interface LogMessagesInfo - String to be written.public void writeStackTrace(java.lang.Exception exc)
writeStackTrace in interface MainCmdLogging_ifcpublic void writeWarning(java.lang.CharSequence sError)
LogMessagewriteWarning in interface LogMessagesError - The error text, it should be without such hot spot words line "!!!WARNING!!!",
because the distinction in display should be done by the implementation of this method.
A good sample is writeErrorln("file is empty: " + sFileName);public void close()
LogMessageclose mean.
If the device is a log file writer it should be clearly.
close may mean, the processing of messages is finite temporary.
An open occurs automatically, if a new message is dispatched.close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface LogMessagepublic void flush()
LogMessageflush mean.
If the device is a log file writer it should be clearly.
flush may mean, the processing of messages is ready to transmit yet.flush in interface LogMessagepublic boolean isOnline()
LogMessageisOnline in interface LogMessagepublic boolean sendMsg(int identNumber,
java.lang.CharSequence text,
java.lang.Object... args)
LogMessage#sendMsg(int, OS_TimeStamp, String, Object...).sendMsg in interface LogMessageidentNumber - of the message. If it is negative, it is the same message as positive number,
but with information 'going state', where the positive number is 'coming state'.text - The text representation of the message, format string, see java.lang.String.format(..).args - 0, 1 or more arguments of any type.
The interpretation of the arguments is controlled by param text.public boolean sendMsgTime(int identNumber,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
java.lang.Object... args)
LogMessagesendMsgTime in interface LogMessageidentNumber - of the message. If it is negative, it is the same message as positive number,
but with information 'going state', where the positive number is 'coming state'.creationTime - absolute time stamp. @Java2C=perValue.text - The text representation of the message, format string, see java.lang.String.format(..).args - 0, 1 or more arguments of any type.
The interpretation of the arguments is controlled by param text.public boolean sendMsgVaList(int identNumber,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
Va_list args)
LogMessage#sendMsg(int, OS_TimeStamp, String, Object...), but the parameter args is varied:sendMsgVaList in interface LogMessagetext - The text of the message: Hint for Java2C: This is a StringJc, not a simple char const*.
That is necessary because the String may be replaced.args - Reference to a buffer which contains the values for a variable argument list.
vprintf(buffer, text, args).
The referenced instance shouldn't accepted as persistent outside processing time
of the called routine. Therefore stack content is able to provide.
public java.lang.Appendable append(java.lang.CharSequence csq)
throws java.io.IOException
append in interface java.lang.Appendablejava.io.IOExceptionpublic java.lang.Appendable append(java.lang.CharSequence csq,
int start,
int end)
throws java.io.IOException
append in interface java.lang.Appendablejava.io.IOExceptionpublic java.lang.Appendable append(char c)
throws java.io.IOException
append in interface java.lang.Appendablejava.io.IOException