public final class LogPrintStream
extends java.io.PrintStream
System.out
and System.err
and the applications using loggers.
Often programmers want all messages be written via logging (expecially exception stack traces).
Normally standard output messages should be logged on the INFO level, those from the error
channel should be logged on the WARNING level.
Remember that the print stream passed to the constructor is simply for proper startup. There
are no messages passed on to this stream but only to the logging engine. The Javadoc comments
of the methods are quite the same that can be found in the API documentation from SUN.
Constructor and Description |
---|
LogPrintStream(java.util.logging.Logger logger,
java.util.logging.Level level)
Constructor.
|
LogPrintStream(java.util.logging.Logger logger,
java.util.logging.Level level,
java.lang.String id)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
java.io.PrintStream |
append(char c)
Appends the specified character to this output stream.
|
java.io.PrintStream |
append(java.lang.CharSequence csq)
Appends the specified character sequence to this output stream.
|
java.io.PrintStream |
append(java.lang.CharSequence csq,
int start,
int end)
Appends a subsequence of the specified character sequence to this output stream.
|
boolean |
checkError()
Flush the stream and check its error state.
|
void |
close()
Close the stream.
|
void |
flush()
Flush the stream.
|
java.io.PrintStream |
format(java.util.Locale l,
java.lang.String format,
java.lang.Object... args)
Writes a formatted string to this output stream using the specified format string and
arguments.
|
java.io.PrintStream |
format(java.lang.String format,
java.lang.Object... args)
Writes a formatted string to this output stream using the specified format string and
arguments.
|
void |
print(boolean b)
Print a boolean value.
|
void |
print(char c)
Print a character.
|
void |
print(char[] s)
Print an array of characters.
|
void |
print(double d)
Print a double-precision floating-point number.
|
void |
print(float f)
Print a floating-point number.
|
void |
print(int i)
Print an integer.
|
void |
print(long l)
Print a long integer.
|
void |
print(java.lang.Object obj)
Print an object.
|
void |
print(java.lang.String s)
Print a string.
|
java.io.PrintStream |
printf(java.util.Locale l,
java.lang.String format,
java.lang.Object... args)
A convenience method to write a formatted string to this output stream using the specified
format string and arguments.
|
java.io.PrintStream |
printf(java.lang.String format,
java.lang.Object... args)
A convenience method to write a formatted string to this output stream using the specified
format string and arguments.
|
void |
println()
Terminate the current line by writing the line separator string.
|
void |
println(boolean x)
Print a boolean and then terminate the line.
|
void |
println(char x)
Print a character and then terminate the line.
|
void |
println(char[] x)
Print an array of characters and then terminate the line.
|
void |
println(double x)
Print a double and then terminate the line.
|
void |
println(float x)
Print a float and then terminate the line.
|
void |
println(int x)
Print an integer and then terminate the line.
|
void |
println(long x)
Print a long and then terminate the line.
|
void |
println(java.lang.Object x)
Print an object and then terminate the line.
|
void |
println(java.lang.String x)
Print a string and then terminate the line.
|
void |
write(byte[] buf,
int off,
int len)
Write len bytes from the specified byte array starting at offset off to this stream.
|
void |
write(int b)
Write the specified byte to this stream.
|
public LogPrintStream(java.util.logging.Logger logger, java.util.logging.Level level)
PrintStream
(in fact no single
byte will be written to it). All output methods are using the given logger instance.
This constructor will lead the stream not to produce any id prefixes for the log lines.
logger
- Logging instancelevel
- Log levelpublic LogPrintStream(java.util.logging.Logger logger, java.util.logging.Level level, java.lang.String id)
PrintStream
(in fact no single
byte will be written to it). All output methods are using the given logger instance. The
optional id
is used as prefix for the logging content. For instance id="out"
leads to the following result: "2006-06-26 20:50:05.875 INFO (out) Some message". Normally
this class is used to substitute System.out
or System.err
, so the
id
can be used to mark this replacement and see what's coming over the stream.
Notice that carriage return and linefeed characters are filtered to have nice log lines.
logger
- Logging instancelevel
- Log levelid
- Prefix for log lines, omitted by passing either null
or empty stringpublic java.io.PrintStream append(char c)
append
in interface java.lang.Appendable
append
in class java.io.PrintStream
c
- The 16-bit character to appendpublic java.io.PrintStream append(java.lang.CharSequence csq)
append
in interface java.lang.Appendable
append
in class java.io.PrintStream
csq
- The character sequence to append. If csq
is null
,
then the four characters "null" are appended to this output stream.public java.io.PrintStream append(java.lang.CharSequence csq, int start, int end)
append
in interface java.lang.Appendable
append
in class java.io.PrintStream
csq
- The character sequence from which a subsequence will be appended. If
csq
is null
, then characters will be appended as if
csq
contained the four characters "null".start
- The index of the first character in the subsequenceend
- The index of the character following the last character in the subsequencejava.lang.IndexOutOfBoundsException
- If start
or end
are negative,
start
is greater than end
, or
end
is greater than csq.length()
.public boolean checkError()
checkError
in class java.io.PrintStream
IOException
other than InterruptedIOException
, or the setError
method
has been invokedpublic void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.PrintStream
public void flush()
flush
in interface java.io.Flushable
flush
in class java.io.PrintStream
public java.io.PrintStream format(java.util.Locale l, java.lang.String format, java.lang.Object... args)
format
in class java.io.PrintStream
l
- The locale to apply during formatting. If l
is null
then no localization is applied.format
- A format string as described in Format string syntaxargs
- Arguments referenced by the format specifiers in the format string. If there
are more arguments than format specifiers, the extra arguments are ignored.
The number of arguments is variable and may be zero. The maximum number of
arguments is limited by the maximum dimension of a Java array as defined by
the Java Virtual Machine Specification. The behaviour on a null
argument depends on the conversion.java.util.IllegalFormatException
- If a format string contains an illegal syntax, a format
specifier that is incompatible with the given arguments,
insufficient arguments given the format string, or other
illegal conditions. For specification of all possible
formatting errors, see the Details section of the formatter
class specification.java.lang.NullPointerException
- If the format is null
public java.io.PrintStream format(java.lang.String format, java.lang.Object... args)
format
in class java.io.PrintStream
format
- A format string as described in Format string syntaxargs
- Arguments referenced by the format specifiers in the format string. If there
are more arguments than format specifiers, the extra arguments are ignored.
The number of arguments is variable and may be zero. The maximum number of
arguments is limited by the maximum dimension of a Java array as defined by
the Java Virtual Machine Specification. The behaviour on a null
argument depends on the conversion.java.util.IllegalFormatException
- If a format string contains an illegal syntax, a format
specifier that is incompatible with the given arguments,
insufficient arguments given the format string, or other
illegal conditions. For specification of all possible
formatting errors, see the Details section of the formatter
class specification.java.lang.NullPointerException
- If the format is null
public void print(boolean b)
print
in class java.io.PrintStream
b
- The boolean to be printedpublic void print(char c)
print
in class java.io.PrintStream
c
- The char to be printedpublic void print(char[] s)
print
in class java.io.PrintStream
s
- The array of chars to be printedjava.lang.NullPointerException
- If s
is null
public void print(double d)
print
in class java.io.PrintStream
d
- The double to be printedpublic void print(float f)
print
in class java.io.PrintStream
f
- The float to be printedpublic void print(int i)
print
in class java.io.PrintStream
i
- The int to be printedpublic void print(long l)
print
in class java.io.PrintStream
l
- The long to be printedpublic void print(java.lang.Object obj)
print
in class java.io.PrintStream
obj
- The object to be printedpublic void print(java.lang.String s)
print
in class java.io.PrintStream
s
- The string to be printedpublic java.io.PrintStream printf(java.util.Locale l, java.lang.String format, java.lang.Object... args)
printf
in class java.io.PrintStream
l
- The locale to apply during formatting. If l
is null
then no localization is applied.format
- A format string as described in Format string syntaxargs
- Arguments referenced by the format specifiers in the format string. If there
are more arguments than format specifiers, the extra arguments are ignored.
The number of arguments is variable and may be zero. The maximum number of
arguments is limited by the maximum dimension of a Java array as defined by
the Java Virtual Machine Specification. The behaviour on a null
argument depends on the conversion.java.util.IllegalFormatException
- If a format string contains an illegal syntax, a format
specifier that is incompatible with the given arguments,
insufficient arguments given the format string, or other
illegal conditions. For specification of all possible
formatting errors, see the Details section of the formatter
class specification.java.lang.NullPointerException
- If the format is null
public java.io.PrintStream printf(java.lang.String format, java.lang.Object... args)
printf
in class java.io.PrintStream
format
- A format string as described in Format string syntaxargs
- Arguments referenced by the format specifiers in the format string. If there
are more arguments than format specifiers, the extra arguments are ignored.
The number of arguments is variable and may be zero. The maximum number of
arguments is limited by the maximum dimension of a Java array as defined by
the Java Virtual Machine Specification. The behaviour on a null
argument depends on the conversion.java.util.IllegalFormatException
- If a format string contains an illegal syntax, a format
specifier that is incompatible with the given arguments,
insufficient arguments given the format string, or other
illegal conditions. For specification of all possible
formatting errors, see the Details section of the formatter
class specification.java.lang.NullPointerException
- If the format is null
public void println()
println
in class java.io.PrintStream
public void println(boolean x)
println
in class java.io.PrintStream
x
- The boolean to be printedpublic void println(char x)
println
in class java.io.PrintStream
x
- The char to be printedpublic void println(char[] x)
println
in class java.io.PrintStream
x
- The array of chars to be printedjava.lang.NullPointerException
- If s
is null
public void println(double x)
println
in class java.io.PrintStream
x
- The double to be printedpublic void println(float x)
println
in class java.io.PrintStream
x
- The float to be printedpublic void println(int x)
println
in class java.io.PrintStream
x
- The int to be printedpublic void println(long x)
println
in class java.io.PrintStream
x
- The long to be printedpublic void println(java.lang.Object x)
println
in class java.io.PrintStream
x
- The object to be printedpublic void println(java.lang.String x)
println
in class java.io.PrintStream
x
- The string to be printedpublic void write(byte[] buf, int off, int len)
write
in class java.io.PrintStream
buf
- A byte arrayoff
- Offset from which to start taking byteslen
- Number of bytes to writepublic void write(int b)
write
in class java.io.PrintStream
b
- The byte to be writtenCopyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.