|
qflib 0.98.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--de.qfs.lib.log.StreamLogWriter | +--de.qfs.lib.log.FileLogWriter
An extension of the StreamLogWriter
that writes
LogEntries
to a File
.
The constructors leave three choices for how the file should be opened:
MODE_CREATE
MODE_APPEND
MODE_UNIQUE
myname.log
,
this will create myname1.log
, the next time its
myname2.log
and so on.
Field Summary | |
protected java.io.File |
file
The log file to write to. |
protected boolean |
keepClosed
Whether to close the log file after each write. |
static int |
MODE_APPEND
Append to a log file, creating a new one if necessary. |
static int |
MODE_CREATE
Create a new log file, overwriting existing files. |
static int |
MODE_UNIQUE
Create a new log file. |
Fields inherited from class de.qfs.lib.log.StreamLogWriter |
closed, format, mustClose, ps, pw |
Constructor Summary | |
FileLogWriter(java.lang.String client,
java.lang.String file)
Create a new FileLogWriter that uses a DefaultLogFormat to write LogEntries to a file. |
|
FileLogWriter(java.lang.String client,
java.lang.String file,
int mode,
boolean keepClosed)
Create a new FileLogWriter that uses a DefaultLogFormat to write LogEntries to a file. |
|
FileLogWriter(java.lang.String client,
java.lang.String file,
int mode,
boolean keepClosed,
LogFormat format)
Create a new FileLogWriter that writes LogEntries to
a file. |
|
FileLogWriter(java.lang.String client,
java.lang.String file,
LogFormat format)
Create a new FileLogWriter that writes LogEntries to
a file. |
Method Summary | |
static LevelFilter |
logToFile(java.lang.String client,
java.lang.String file,
int mode,
boolean keepClosed)
Log messages to a log file by creating a LevelFilter with a FileLogWriter and adding it to the Log filter chain. |
static LevelFilter |
logToFile(java.lang.String client,
java.lang.String file,
int mode,
boolean keepClosed,
LogFormat format)
Log messages to a log file by creating a LevelFilter with a FileLogWriter and adding it to the Log filter chain. |
protected void |
openFile(java.lang.String client,
java.lang.String filename,
int mode)
Open the file for writing. |
static void |
stopLogging()
Remove the last LevelFilter instance created with
logToFile from the filter chain and close the log
file. |
void |
write(LogEntry entry)
Write one LogEntry. |
void |
write(LogEntry[] entries)
Write an array of LogEntires in one go. |
Methods inherited from class de.qfs.lib.log.StreamLogWriter |
close, getFormat, setFormat |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int MODE_CREATE
public static final int MODE_APPEND
public static final int MODE_UNIQUE
protected java.io.File file
protected boolean keepClosed
Constructor Detail |
public FileLogWriter(java.lang.String client, java.lang.String file) throws java.io.IOException
DefaultLogFormat
to write LogEntries
to a file.client
- Name of the client, used by qflog.file
- The name of the file to print to.java.io.IOException
- If the file cannot be opened for writing.public FileLogWriter(java.lang.String client, java.lang.String file, int mode, boolean keepClosed) throws java.io.IOException
DefaultLogFormat
to write LogEntries
to a file.client
- Name of the client, used by qflog.file
- The name of the file to print to.mode
- How the file should be created. Must be one of
MODE_CREATE
, MODE_APPEND
, or MODE_UNIQUE
.keepClosed
- Whether to close the file after each write.java.io.IOException
- If the file cannot be opened for writing.public FileLogWriter(java.lang.String client, java.lang.String file, LogFormat format) throws java.io.IOException
LogEntries
to
a file.client
- Name of the client, used by qflog.file
- The name of the file to print to.format
- The format used to print LogEntries.java.io.IOException
- If the file cannot be opened for writing.public FileLogWriter(java.lang.String client, java.lang.String file, int mode, boolean keepClosed, LogFormat format) throws java.io.IOException
LogEntries
to
a file.client
- Name of the client, used by qflog.file
- The name of the file to print to.mode
- How the file should be created. Must be one of
MODE_CREATE
, MODE_APPEND
, or MODE_UNIQUE
.keepClosed
- Whether to close the file after each write.format
- The format used to print LogEntries.java.io.IOException
- If the file cannot be opened for writing.Method Detail |
public static LevelFilter logToFile(java.lang.String client, java.lang.String file, int mode, boolean keepClosed) throws java.io.IOException
client
- Name of the client, used by qflog.file
- The name of the file to save in.mode
- How the file should be created. Must be one of
MODE_CREATE
, MODE_APPEND
, or MODE_UNIQUE
.keepClosed
- Whether to close the file after each write.LevelFilter.setLevel
, it will log
all messages to the file. If you only call this method once in your
application, you can use stopLogging
to remove the
filter and close the writer, otherwise you have to save this reference
to the filter and clean up yourself.java.io.IOException
- If the file cannot be created.public static LevelFilter logToFile(java.lang.String client, java.lang.String file, int mode, boolean keepClosed, LogFormat format) throws java.io.IOException
client
- Name of the client, used by qflog.file
- The name of the file to save in.mode
- How the file should be created. Must be one of
MODE_CREATE
, MODE_APPEND
, or MODE_UNIQUE
.keepClosed
- Whether to close the file after each write.format
- The format used to print LogEntries.LevelFilter.setLevel
, it will log
all messages to the file. If you only call this method once in your
application, you can use stopLogging
to remove the
filter and close the writer, otherwise you have to save this reference
to the filter and clean up yourself.java.io.IOException
- If the file cannot be created.public static void stopLogging()
LevelFilter
instance created with
logToFile
from the filter chain and close the log
file. Use this method if you only call logToFile
once in your application.public void write(LogEntry entry)
write
in class StreamLogWriter
entry
- The entry to write.public void write(LogEntry[] entries)
write(LogEntry)
, since it is more efficient.write
in class StreamLogWriter
entries
- The entries to write.protected void openFile(java.lang.String client, java.lang.String filename, int mode) throws java.io.IOException
client
- Name of the client, used by qflog.mode
- How the file should be created. Must be one of
MODE_CREATE
, MODE_APPEND
, or MODE_UNIQUE
.java.io.IOException
- If the file cannot be opened.
|
qflib 0.98.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |