Class SimpleWriter
- java.lang.Object
-
- com.elvishew.xlog.printer.file.writer.Writer
-
- com.elvishew.xlog.printer.file.writer.SimpleWriter
-
public class SimpleWriter extends Writer
A simple implementation ofWriter.Subclass can override
onNewFileCreated(File)and do some initialization work to the new file, such as callingappendLog(String)to add a file header.- Since:
- 1.11.0
-
-
Constructor Summary
Constructors Constructor Description SimpleWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendLog(java.lang.String log)Append the log to the end of the opened log file, normally an extra line separator is needed.booleanclose()Make sure the opened log file is closed, normally called before switching the log file.java.io.FilegetOpenedFile()Get the opened log file.java.lang.StringgetOpenedFileName()Get the name of opened log file.booleanisOpened()Whether a log file is successfully opened in previousWriter.open(File).voidonNewFileCreated(java.io.File file)Called after a log file is newly created.booleanopen(java.io.File file)Open a specific log file for future writing, if it doesn't exist yet, just create it.
-
-
-
Method Detail
-
open
public boolean open(java.io.File file)
Description copied from class:WriterOpen a specific log file for future writing, if it doesn't exist yet, just create it.
-
isOpened
public boolean isOpened()
Description copied from class:WriterWhether a log file is successfully opened in previousWriter.open(File).
-
getOpenedFile
public java.io.File getOpenedFile()
Description copied from class:WriterGet the opened log file.- Specified by:
getOpenedFilein classWriter- Returns:
- the opened log file, or null if log file not opened
-
getOpenedFileName
public java.lang.String getOpenedFileName()
Description copied from class:WriterGet the name of opened log file.- Specified by:
getOpenedFileNamein classWriter- Returns:
- the name of opened log file, or null if log file not opened
-
onNewFileCreated
public void onNewFileCreated(java.io.File file)
Called after a log file is newly created.You can do some initialization work to the new file, such as calling
appendLog(String)to add a file header.Called in worker thread.
- Parameters:
file- the newly create log file
-
appendLog
public void appendLog(java.lang.String log)
Description copied from class:WriterAppend the log to the end of the opened log file, normally an extra line separator is needed.
-
-