|
SoftNet-Consult Java Utility Library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.softnetConsult.utils.log.ScreenFileLogger
public class ScreenFileLogger
This class provides a convenient way to direct text output to the screen (std-out) and to a file (file stream) at the same time, in addition it provides an easy way to make sure that all output is indented according to a specifiable level; this makes this class ideal for simple logging and tracking tasks.
This product includes software developed by the
SoftNet-Consult Java Utility Library project and its contributors.
(http://java-tools.sourceforge.net)
Copyright (c) 2007-2008 SoftNet-Consult.
Copyright (c) 2007-2008 G. Paperin.
All rights reserved.
File: ScreenFileLogger.java
Library API version: "2.02"
Java compliance version: "1.5"
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following terms and conditions are met:
1. Redistributions of source code must retain the above
acknowledgement of the SoftNet-Consult Java Utility Library project, the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above acknowledgement of the
SoftNet-Consult Java Utility Library project, the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
3. All advertising materials mentioning features or use of this software or any derived
software must display the following acknowledgement:
This product includes software developed by the SoftNet-Consult Java Utility Library
project and its contributors.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Field Summary | |
---|---|
private boolean |
fileAppend
Whether to append or overwrite when output file is (re)opened. |
private java.io.FileOutputStream |
fileStream
Output file stream. |
private java.lang.String |
indentation
Indentation string (one copy per level). |
private int |
indentLevel
Current indentation level. |
private boolean |
indentNext
Whether to indent next output. |
private java.io.File |
logFile
Output file. |
static int |
MAX_INDENT_LEVEL
Maximum indentation level permitted. |
private com.softnetConsult.utils.streams.MultiPrintStream |
outs
Aggregating output stream. |
Constructor Summary | |
---|---|
ScreenFileLogger(boolean logToScreen,
boolean logToFile,
java.io.File logFile,
boolean append,
java.lang.String indentation)
Creates a logger that can write all logged output to screen (or whatever is the current std-out) and/or to a file. |
|
ScreenFileLogger(boolean logToScreen,
boolean logToFile,
java.lang.String logFileName,
boolean append,
java.lang.String indentation)
Creates a logger that can write all logged output to screen (or whatever is the current std-out) and/or to a file. |
Method Summary | |
---|---|
void |
close()
Closes this logger and a possibly open file stream. |
void |
decIndentLevel()
Decrements the current indentation level. |
private void |
doIndentation()
Used internally to generate a correct indentation string. |
protected void |
finalize()
Ensures that all associated streams are closed when this logger is finalised. |
java.io.File |
getFile()
Gets the file associated with this logger (regardless of whether this logger currently logs to a file). |
int |
getIndentLevel()
Gets the current indentation level. |
boolean |
getLogToFile()
Checks whether this logger currently writes to a file. |
boolean |
getLogToScreen()
Checks whether this logger currently writes to the screen (std-out). |
void |
incIndentLevel()
Increments the current indentation level. |
void |
print(boolean val)
Prints the specified value to std-out and/or file. |
void |
print(char val)
Prints the specified value to std-out and/or file. |
void |
print(char[] s)
Prints a string to std-out and/or file. |
void |
print(double val)
Prints the specified value to std-out and/or file. |
void |
print(float val)
Prints the specified value to std-out and/or file. |
void |
print(int val)
Prints the specified value to std-out and/or file. |
void |
print(long val)
Prints the specified value to std-out and/or file. |
void |
print(java.lang.Object o)
Prints an object to std-out and/or file. |
void |
print(java.lang.String s)
Prints a string to std-out and/or file. |
void |
print(java.lang.Throwable t)
Prints extended information about a Thowable
(including stack trace) to std-out and/or file. |
void |
printf(java.lang.String format,
java.lang.Object... args)
Logs a formated string to std-out and/or file following the format specification defined for String.format(String, Object[]) . |
void |
println()
Initiates a new line by emitting a new-line character to std-out and/or file. |
void |
println(boolean val)
Prints the specified value followed by a new line to std-out and/or file. |
void |
println(char val)
Prints the specified value followed by a new line to std-out and/or file. |
void |
println(char[] s)
Prints a string followed by a new line to std-out and/or file. |
void |
println(double val)
Prints the specified value followed by a new line to std-out and/or file. |
void |
println(float val)
Prints the specified value followed by a new line to std-out and/or file. |
void |
println(int val)
Prints the specified value followed by a new line to std-out and/or file. |
void |
println(long val)
Prints the specified value followed by a new line to std-out and/or file. |
void |
println(java.lang.Object o)
Prints an object followed by a new line to std-out and/or file. |
void |
println(java.lang.String s)
Prints a string followed by a new line to std-out and/or file. |
void |
println(java.lang.Throwable t)
Prints extended information about a Thowable (including stack
trace) followed by a new line to std-out and/or file. |
void |
setIndentLevel(int indentLevel)
Sets the indentation level to the specicied value. |
void |
setLogToFile(boolean logToFile)
Sets whether this logger will write to a for the subsequent print-actions. |
void |
setLogToScreen(boolean logToScreen)
Sets whether this logger will write to the screen (std-out) for the subsequent print-actions. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAX_INDENT_LEVEL
private java.lang.String indentation
private boolean indentNext
private int indentLevel
private java.io.File logFile
private java.io.FileOutputStream fileStream
private boolean fileAppend
private com.softnetConsult.utils.streams.MultiPrintStream outs
Constructor Detail |
---|
public ScreenFileLogger(boolean logToScreen, boolean logToFile, java.lang.String logFileName, boolean append, java.lang.String indentation) throws java.io.FileNotFoundException
logToScreen
- Whether to start logging to std-out (can be changed later).logToFile
- Whether to start logging to a file (can be changed later if file is specified).logFileName
- File name to write to.append
- Append or overwrite the file.indentation
- Indentation string (one copy per indentation level).
java.io.FileNotFoundException
- If there is a problem when opening the specified file for writing.public ScreenFileLogger(boolean logToScreen, boolean logToFile, java.io.File logFile, boolean append, java.lang.String indentation) throws java.io.FileNotFoundException
logToScreen
- Whether to start logging to std-out (can be changed later).logToFile
- Whether to start logging to a file (can be changed later if file is specified).logFile
- File to write to.append
- Append or overwrite the file.indentation
- Indentation string (one copy per indentation level).
java.io.FileNotFoundException
- If there is a problem when opening the specified file for writing.Method Detail |
---|
public java.io.File getFile()
public boolean getLogToScreen()
public void setLogToScreen(boolean logToScreen)
logToScreen
- Whther to write to System.out
or not.public boolean getLogToFile()
public void setLogToFile(boolean logToFile) throws java.io.FileNotFoundException
null
,
an attempt to turn file-logging on will raise an IllegalArgumentException
.append
parameter in the constructor.
logToFile
- Whether to log to a file or not.
java.io.FileNotFoundException
- If there is a problem when opening the file.public void close()
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void setIndentLevel(int indentLevel)
indentLevel
copies of
the indentation
-string.
indentLevel
- The new indentation level.public int getIndentLevel()
public void incIndentLevel()
indentLevel
copies of
the indentation
-string.
public void decIndentLevel()
indentLevel
copies of
the indentation
-string.
private void doIndentation()
public void printf(java.lang.String format, java.lang.Object... args)
String.format(String, Object[])
.
format
- The format string.args
- The value arguments.public void print(java.lang.Object o)
o
- Object to print.public void print(java.lang.Throwable t)
Thowable
(including stack trace) to std-out and/or file.
t
- Object to print.public void print(java.lang.String s)
s
- String to print.public void print(char[] s)
s
- String to print.public void print(boolean val)
val
- The value to print.public void print(char val)
val
- The value to print.public void print(int val)
val
- The value to print.public void print(long val)
val
- The value to print.public void print(float val)
val
- The value to print.public void print(double val)
val
- The value to print.public void println()
public void println(java.lang.Object o)
o
- Object to print.public void println(java.lang.Throwable t)
Thowable
(including stack
trace) followed by a new line to std-out and/or file.
Next output will be indented accoring to the current indentation level.
t
- Object to print.public void println(java.lang.String s)
s
- Object to print.public void println(char[] s)
s
- Object to print.public void println(boolean val)
val
- Value to print.public void println(char val)
val
- Value to print.public void println(int val)
val
- Value to print.public void println(long val)
val
- Value to print.public void println(float val)
val
- Value to print.public void println(double val)
val
- Value to print.
|
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |