|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
cdx.scorebot.util.io.FlexLogger
public class FlexLogger
Provide easy means of outputting to both the terminal and file(s) at the same time
Change Log:
getStreamCount
which returns the number of streams
currently being logged to.
FlexLogger
a PrintStream
itself so it
could be passed wherever streams can be passed and print to all of its
log files.
Field Summary | |
---|---|
static int |
APPEND
if file exists, append to the old file |
static boolean |
DEFAULT_MULTIPLES_ALLOWED
whether or not multiple instances of the same stream is permitted by default (only blocks the streams for which OutputStream.equals returns true). |
static int |
DEFAULT_NUMBERING_LEN
default number of digits to append to filenames being reused by default when renaming files |
static boolean |
DONT_LOG_TO_CONSOLE
do not log to the console |
static boolean |
LOG_TO_CONSOLE
log to the console |
static int |
OVERWRITE
if file exists, overwrite the old file |
static int |
RENAME
If the file already exists, the old file will be renamed as oldname.### where ### is the earliest number which constitutes an unused filename; ### is a n-digit number specified by the getNumberingLen (defaults to DEFAULT_NUMBERING_LEN . |
Fields inherited from class java.io.FilterOutputStream |
---|
out |
Constructor Summary | |
---|---|
FlexLogger()
Creates a FlexLogger which will log only to the System.out PrintStream |
|
FlexLogger(boolean sysOut)
Creates a FlexLogger which will log to the console as specified. |
|
FlexLogger(java.lang.String filename)
Creates a FlexLogger which is initialized with the one specified stream to log to. |
|
FlexLogger(java.lang.String filename,
boolean sysOut)
Creates a FlexLogger which is initialized with the one specified stream to log to with an
option to log to the console too. |
|
FlexLogger(java.lang.String filename,
boolean sysOut,
int alreadyExistsHandling)
Creates a FlexLogger which is initialized with the one specified stream to log to with an
option to log to the console too; if the file already exists, the alreadyExistsHandling
argument species how to handle this. |
|
FlexLogger(java.lang.String filename,
int numDigits,
boolean sysOut)
Creates a FlexLogger which is initialized with the one specified stream to log to with an
option to log to the console too; if the file already exists, the old file will be renamed;
numDigits indicates how many digits to use when renaming any old file. |
Method Summary | |
---|---|
boolean |
addOutputSource(java.io.PrintStream ps)
Adds the specified PrintStream to the list of streams to log to |
java.io.PrintStream |
addOutputSource(java.lang.String filename)
Opens the specified filename and adds it to the list of streams to log to |
java.io.PrintStream |
addOutputSource(java.lang.String filename,
int alreadyExistsHandling)
Opens the specified filename and adds it to the list of streams to log to |
void |
close()
Close all streams except System.out/err (if either System.out or err is one of the streams in this). |
int |
getNumberingLen()
get how many digits will be (at a minimum) in the filename |
int |
getNumStreams()
returns the number of active streams |
boolean |
isAllowDuplicateStreams()
get whether duplicate streams are allowed |
boolean |
isPrefixingTimestamp()
gets whether or not a timestamp will be prefixed to string output |
static boolean |
isValidFileExistsFlag(int alreadyExistsHandling)
determine whether or not the flag passed is a valid file exists flag operation |
static void |
main(java.lang.String[] args)
See if we can output two places at once |
void |
prefix()
Write the current timestamp followed by ': ' to all streams |
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. |
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 |
removeOutputSource(java.io.PrintStream ps)
Removes all instances of the specified PrintStream from the list of streams to log to |
void |
removeOutputSource(java.lang.String filename)
Stops logging to the specified filename (only affects logging streams which were added by filename; if they were added by PrintStream then it must be removed by removeOutputSource(PrintStream) ) |
void |
setAllowDuplicateStreams(boolean allowDuplicateStreams)
set whether duplicate streams are allowed (will only apply to streams added in the future) |
void |
setNumberingLen(int numberingLen)
set how many digits to have at a minimum in the filename |
void |
setPrefixTimestamp(boolean prefixTimestamp)
sets whether or not a timestamp will be prefixed to string output |
java.lang.String |
toString()
Names of the files which this is outputting to |
void |
write(byte[] buf,
int off,
int len)
Write len bytes from the specified byte array starting at
offset off to these streams. |
void |
write(int b)
Write the specified byte to these streams. |
Methods inherited from class java.io.PrintStream |
---|
append, append, append, checkError, clearError, flush, format, format, printf, printf, setError |
Methods inherited from class java.io.FilterOutputStream |
---|
write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final boolean LOG_TO_CONSOLE
public static final boolean DONT_LOG_TO_CONSOLE
public static final int DEFAULT_NUMBERING_LEN
public static final boolean DEFAULT_MULTIPLES_ALLOWED
OutputStream.equals
returns true).
public static final int RENAME
getNumberingLen
(defaults to DEFAULT_NUMBERING_LEN
.
public static final int APPEND
public static final int OVERWRITE
Constructor Detail |
---|
public FlexLogger()
FlexLogger
which will log only to the System.out PrintStream
public FlexLogger(boolean sysOut)
FlexLogger
which will log to the console as specified.
sysOut
- whether or not to log to System.out
initiallypublic FlexLogger(java.lang.String filename) throws java.io.FileNotFoundException
FlexLogger
which is initialized with the one specified stream to log to.
filename
- The name of the file to log. If the file already exists, the old file will be renamed.
java.io.FileNotFoundException
- filename does not exist or cannot be opened for writeRENAME
public FlexLogger(java.lang.String filename, boolean sysOut) throws java.io.FileNotFoundException
FlexLogger
which is initialized with the one specified stream to log to with an
option to log to the console too.
filename
- The name of the file to log. If the file already exists, the old file will be renamed.sysOut
- whether or not to log to System.out
initially
java.io.FileNotFoundException
- filename does not exist or cannot be opened for writeRENAME
public FlexLogger(java.lang.String filename, boolean sysOut, int alreadyExistsHandling) throws java.io.FileNotFoundException
FlexLogger
which is initialized with the one specified stream to log to with an
option to log to the console too; if the file already exists, the alreadyExistsHandling
argument species how to handle this.
filename
- The name of the file to log. If the file already exists, the old file will be renamed.sysOut
- whether or not to log to System.out
initiallyalreadyExistsHandling
- how to handle the file if it already exists. There are three distinct ways to handle
this: 1)FlexLogger.APPEND
2)FlexLogger.OVERWRITE
3)FlexLogger.RENAME
java.io.FileNotFoundException
- filename does not exist or cannot be opened for writepublic FlexLogger(java.lang.String filename, int numDigits, boolean sysOut) throws java.io.FileNotFoundException
FlexLogger
which is initialized with the one specified stream to log to with an
option to log to the console too; if the file already exists, the old file will be renamed;
numDigits
indicates how many digits to use when renaming any old file.
filename
- The name of the file to log. If the file already exists, the old file will be renamed.numDigits
- how many digits to have at a minimum in the filenamesysOut
- whether or not to log to System.out
initially
java.io.FileNotFoundException
- filename does not exist or cannot be opened for writeAPPEND
,
OVERWRITE
,
RENAME
Method Detail |
---|
public static boolean isValidFileExistsFlag(int alreadyExistsHandling)
alreadyExistsHandling
- how to handle the file if it already exists. There are three distinct ways to handle
this: 1)FlexLogger.APPEND
2)FlexLogger.OVERWRITE
3)FlexLogger.RENAME
true
if the flag is validpublic static void main(java.lang.String[] args) throws java.io.FileNotFoundException
args
- command line arguments
java.io.FileNotFoundException
- filename does not exist or cannot be opened for writepublic java.io.PrintStream addOutputSource(java.lang.String filename) throws java.io.FileNotFoundException
filename
- The name of the file to log. If the file already exists, the old file will be renamed.
PrintStream
created for the specified filename, or null if not added
java.io.FileNotFoundException
- filename does not exist or cannot be opened for writeRENAME
public java.io.PrintStream addOutputSource(java.lang.String filename, int alreadyExistsHandling) throws java.io.FileNotFoundException
filename
- The name of the file to logalreadyExistsHandling
- how to handle the file if it already exists.
PrintStream
created for the specified filename, or null if not added
java.io.FileNotFoundException
- filename does not exist or cannot be opened for writeAPPEND
,
OVERWRITE
,
RENAME
public boolean addOutputSource(java.io.PrintStream ps)
PrintStream
to the list of streams to log to
ps
- the PrintStream
to log
PrintStream
passed in and added to the list of streams to be
logged toisAllowDuplicateStreams()
public void removeOutputSource(java.lang.String filename)
PrintStream
then it must be removed by removeOutputSource(PrintStream)
)
filename
- the filename of the file to stop logging to (case-sensitive)public void removeOutputSource(java.io.PrintStream ps)
PrintStream
from the list of streams to log to
ps
- the PrintStream
to remove from loggingpublic boolean isAllowDuplicateStreams()
public void setAllowDuplicateStreams(boolean allowDuplicateStreams)
allowDuplicateStreams
- true if duplicates allowedpublic int getNumberingLen()
public void setNumberingLen(int numberingLen)
numberingLen
- number of digitspublic int getNumStreams()
PrintStream
streams being logged topublic boolean isPrefixingTimestamp()
public void setPrefixTimestamp(boolean prefixTimestamp)
prefixTimestamp
- true if timestamps are to be prefixedpublic void prefix()
public void close()
close
in interface java.io.Closeable
close
in class java.io.PrintStream
OutputStream.close()
public void write(int b)
flush
method will be
invoked.
Note that the byte is written as given; to write a character that
will be translated according to the platform's default character
encoding, use the print(char)
or println(char)
methods.
write
in class java.io.PrintStream
b
- The byte to be writtenprint(char)
,
println(char)
public void write(byte[] buf, int off, int len)
len
bytes from the specified byte array starting at
offset off
to these streams. If automatic flushing is
enabled then the flush
method will be invoked.
Note that the bytes will be written as given; to write characters
that will be translated according to the platform's default character
encoding, use the print(char)
or println(char)
methods.
write
in class java.io.PrintStream
buf
- A byte arrayoff
- Offset from which to start taking byteslen
- Number of bytes to writepublic void print(boolean b)
String.valueOf(boolean)
is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the
write(int)
method.
print
in class java.io.PrintStream
b
- The boolean
to be printedpublic void print(char c)
write(int)
method.
print
in class java.io.PrintStream
c
- The char
to be printedpublic void print(int i)
String.valueOf(int)
is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the
write(int)
method.
print
in class java.io.PrintStream
i
- The int
to be printedInteger.toString(int)
public void print(long l)
String.valueOf(long)
is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the
write(int)
method.
print
in class java.io.PrintStream
l
- The long
to be printedLong.toString(long)
public void print(float f)
String.valueOf(float)
is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the
write(int)
method.
print
in class java.io.PrintStream
f
- The float
to be printedFloat.toString(float)
public void print(double d)
String.valueOf(double)
is translated into
bytes according to the platform's default character encoding, and these
bytes are written in exactly the manner of the write(int)
method.
print
in class java.io.PrintStream
d
- The double
to be printedDouble.toString(double)
public void print(char[] s)
write(int)
method.
print
in class java.io.PrintStream
s
- The array of chars to be printedpublic void print(java.lang.String s)
null
then the string
"null"
is printed. Otherwise, the string's characters are
converted into bytes according to the platform's default character
encoding, and these bytes are written in exactly the manner of the
write(int)
method.
print
in class java.io.PrintStream
s
- The String
to be printedpublic void print(java.lang.Object obj)
String.valueOf(Object)
method is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the
write(int)
method.
print
in class java.io.PrintStream
obj
- The Object
to be printedObject.toString()
public void println()
line.separator
, and is not necessarily a single newline
character ('\n'
).
println
in class java.io.PrintStream
public void println(boolean x)
print(boolean)
and then
println()
.
println
in class java.io.PrintStream
x
- The boolean
to be printedpublic void println(char x)
print(char)
and then
println()
.
println
in class java.io.PrintStream
x
- The char
to be printed.public void println(int x)
print(int)
and then
println()
.
println
in class java.io.PrintStream
x
- The int
to be printed.public void println(long x)
print(long)
and then
println()
.
println
in class java.io.PrintStream
x
- a The long
to be printed.public void println(float x)
print(float)
and then
println()
.
println
in class java.io.PrintStream
x
- The float
to be printed.public void println(double x)
print(double)
and then
println()
.
println
in class java.io.PrintStream
x
- The double
to be printed.public void println(char[] x)
print(char[])
and
then println()
.
println
in class java.io.PrintStream
x
- an array of chars to print.public void println(java.lang.String x)
print(String)
and then
println()
.
println
in class java.io.PrintStream
x
- The String
to be printed.public void println(java.lang.Object x)
print(Object)
and then
println()
.
println
in class java.io.PrintStream
x
- The Object
to be printed.public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |