public class MsgPrintStream extends java.lang.Object implements MsgPrintStream_ifc
System.err.println("Source of message - short message; some additional " + information);This is a form which may be proper outside this class too. One should inform about the source of the message, then what's happen, then some more information. If one uses a semicolon as separator, it's able to present such messages for example in an Excel sheet.
System.err
or System.out
to the message system: The LogMessage
interface
needs a number to identify the message, the MsgDispatcher
needs numbers to dispatch. If any identification string is used the first time, a number is created automatically.
If the same start text is used a second one (especially if an output was invoked a second time), the start text
is identified and the same number is used. One can sort messages with that number.
"Source - second division" "Source-specification - second division" "Source-second division"the message dispatcher can deal with ranges.
setMsgIdents(MsgText_ifc)
.
This can be used in conclusion with MsgConfig.setMsgDispaching(MsgDispatcher, String)
to set the dispatching of this message.
Modifier and Type | Class and Description |
---|---|
private static class |
MsgPrintStream.GroupIdent |
private class |
MsgPrintStream.PrintStreamAdapter |
Modifier and Type | Field and Description |
---|---|
private int |
identGroupLast |
private int |
identLast |
private java.util.Map<java.lang.String,MsgPrintStream.GroupIdent> |
idxGroupIdent |
private java.util.Map<java.lang.String,java.lang.Integer> |
idxIdent
Map of all Strings to an message ident number.
|
private LogMessage |
logOut |
private java.util.concurrent.atomic.AtomicInteger |
nextGroupIdent |
private java.util.concurrent.atomic.AtomicInteger |
nextIdent |
protected java.io.OutputStream |
outStream
This class is used for all outputs to the
MsgPrintStream.PrintStreamAdapter which are not
gathered by the overridden methods of PrintStream. |
static int |
version
Version, history and license.
|
private int |
zGroup |
Constructor and Description |
---|
MsgPrintStream(LogMessage logOut,
int identStart,
int sizeNoGroup,
int sizeGroup)
Constructs.
|
Modifier and Type | Method and Description |
---|---|
protected void |
convertToMsg(java.lang.String pre,
java.lang.CharSequence identString,
java.lang.Object... args) |
private MsgPrintStream.GroupIdent |
getMsgGroupIdent(java.lang.String pre,
java.lang.String msg) |
java.io.PrintStream |
getPrintStreamLog(java.lang.String pre)
Returns the PrintStream which converts and redirects the output String to the given LogMessage output.
|
boolean |
setMsgGroupIdent(java.lang.String sIdent,
int nrStart,
int nrLast)
Creates a group with the given text and the given ident number range.
|
void |
setMsgIdents(MsgText_ifc src)
Sets all associations between a message identification text to its ident number or to its number range.
|
public static final int version
MsgPrintStream.PrintStreamAdapter.append(CharSequence)
because it is invoked
in the PrintStream
and should overridden to output the text. Note that one of the core
methods of PrintStream is write(...) but that is private.
MsgPrintStream.PrintStreamAdapter.print(String)
does not dispatch the text directly
but does append it to an internal line buffer till an newline "\n" is detected. It is because the
super method append(CharSequence) calls this method. A PrintStream can be referred as Appendable
and the output can be done with ref.append("start - string;").append(parameter).append("\n") too!
setMsgGroupIdent(String, int, int)
to handle message dispatching
with known or probably texts.
#getPrintStreamLog()
to set System.setOut(...) and System.setErr(...).
private final LogMessage logOut
private final java.util.concurrent.atomic.AtomicInteger nextIdent
private final int identLast
private final java.util.concurrent.atomic.AtomicInteger nextGroupIdent
private final int identGroupLast
private final int zGroup
private final java.util.Map<java.lang.String,java.lang.Integer> idxIdent
private final java.util.Map<java.lang.String,MsgPrintStream.GroupIdent> idxGroupIdent
protected final java.io.OutputStream outStream
MsgPrintStream.PrintStreamAdapter
which are not
gathered by the overridden methods of PrintStream.
There should not be such methods. Therefore the write-methods is not called.
But the outStream should not be empty.public MsgPrintStream(LogMessage logOut, int identStart, int sizeNoGroup, int sizeGroup)
MsgPrintStream myPrintStream = new MsgPrintStream(myMsgDispatcher, 10000, 5000, 100);In this example the range from 1 to 9999 is used for messages which have a defined number outside of this class. Any not numbered message is assigned in the range from 10000 till 149999 if it hasn't a group division, and in groups with the start numbers 15000, 15100 etc. (till 32699 there are 176 groups). Note that the range which can be used is the positive integer range from 0 to about 2000000000. It may be better able to read to have not so large numbers, but there are able to use. Note that you would not have so far different message texts.
logOut
- The output where all messages are written after identifier number building.
The MsgDispatcher
instance is proper to use.identStart
- The first automatically created number used for non grouped message.
Note that other messages have a known fixed number. Use a separate range in the positiv Integers range.sizeNoGroup
- number of the non grouped message identifiers. After this range the grouped messages starts.
Use a high enough number such as 1000 or 10000 or more.sizeGroup
- Size of any group. Use a middle-high enough number such as 100 or 1000.
There won't be more as 1000 several message texts in one group - usually.public java.io.PrintStream getPrintStreamLog(java.lang.String pre)
System.setOut(myMsgPrintStream.getPrintStreamLog("out.")); System.setErr(myMsgPrintStream.getPrintStreamLog("err."));Then any output to System.out.print... and System.err.print... will be redirected to the
LogMessage
association
given in the constructor of this class. One can create so much as necessary adapters. They uses the same association
index between String and list. If the texts are given with setMsgIdents(MsgText_ifc)
without the prefix
they produces the same message ident number. If the text are given with the prefix, the ident numbers are different.
If the association between text and ident is not given before the first call of PrintStream.print..., different prefixes
causes different message idents. In this kind for example System.out and System.err can be redirected to different
message ident numbers though the output texts are the same.
System.setOut(systemPrintAdapter.getPrintStreamLog("out.")); //instead writing to console the PrintStream creates a message System.setErr(systemPrintAdapter.getPrintStreamLog("err.")); //and sends it to the message dispatcher.
public void setMsgIdents(MsgText_ifc src)
getPrintStreamLog(String)
was build.
MsgText_ifc.MsgConfigItem
contains a MsgText_ifc.MsgConfigItem.identText
it is associated
to its number from MsgText_ifc.MsgConfigItem.identNr
or its range to MsgText_ifc.MsgConfigItem.identNrLast
stored in this class (idxIdent
or idxGroupIdent
). If any text is outputted via any
MsgPrintStream.PrintStreamAdapter.print(String)
or MsgPrintStream.PrintStreamAdapter.printf(String, Object...)
and this text
has the same start text, this message ident number is taken. The ident numbers can be used to configure a message dispatcher
independent but proper to this functionality from the same src. In this kind the messages with identification by text
are dispatched accurately.setMsgIdents
in interface MsgPrintStream_ifc
src
- The source of association betwenn text and number.public boolean setMsgGroupIdent(java.lang.String sIdent, int nrStart, int nrLast)
sIdent
- The text till the exclusive " - " separation.nrStart
- The first number of the groupnrLast
- The last number of the group.private MsgPrintStream.GroupIdent getMsgGroupIdent(java.lang.String pre, java.lang.String msg)
protected void convertToMsg(java.lang.String pre, java.lang.CharSequence identString, java.lang.Object... args)