public class FilePrinter extends AbsPrinter implements Closeable
Modifier and Type | Class and Description |
---|---|
static interface |
FilePrinter.FileNameGenerator
The interface to generate new log file.
|
static class |
FilePrinter.TimingFileNameGenerator |
Modifier and Type | Field and Description |
---|---|
protected static String |
DIR_EXT_FILES
Place holder string for the external files dir.
|
protected static String |
DIR_EXT_ROOT
Place holder string for the external storage root dir.(requires WRITE PERMISSION)
|
protected static String |
DIR_INT_FILES
Place holder string for the internal files dir.
|
Constructor and Description |
---|
FilePrinter(Context context)
Create a file printer using default path (external files dir).
|
FilePrinter(Context context,
String logFilePath)
Create a file printer using specified path.
|
FilePrinter(Context context,
String filePath,
FilePrinter.FileNameGenerator generator,
long fileSizeLimit)
Create a file printer.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close associated files, etc.
|
protected String |
createPrintText(int level,
String tag,
String msg)
Override this method to redefine your preferred output format.
|
String |
getLogFilePath()
Get the absolute path for log files.
|
void |
print(int level,
String tag,
String msg)
Do the real output operation, e.g.
|
protected void |
printFileHeader(PrintStreamPrinter printer)
This method provides a quick method to provide file header, e.g.
|
getFormatter, getMaxLengthPerLine, getSoftWrapper, getStyle, onIntercept, setFormatter, setInterceptor, setSoftWrapper, setStyle
protected static final String DIR_INT_FILES
Context.getFilesDir()
,
Constant Field Valuesprotected static final String DIR_EXT_FILES
protected static final String DIR_EXT_ROOT
public FilePrinter(@NonNull Context context) throws IllegalStateException
IllegalStateException
- If try to use external storage but external storage
is unavailable.public FilePrinter(@NonNull Context context, @NonNull String logFilePath) throws IllegalStateException
logFilePath
- absolute path; may use predefined placeholders in start. Currently
supported placeholders: DIR_INT_FILES
, DIR_EXT_FILES
,
DIR_EXT_ROOT
.IllegalStateException
- If try to use external storage but external storage
is unavailable.public FilePrinter(@NonNull Context context, @NonNull String filePath, @NonNull FilePrinter.FileNameGenerator generator, long fileSizeLimit) throws IllegalStateException
fileSizeLimit
- file size limit. By default a single log file would not over 1M.
If a non-positive integer is provided, log files has no size limit.generator
- a generator to provide filename when creating new log file.IllegalStateException
public void print(int level, @NonNull String tag, @NonNull String msg)
Printer
protected void printFileHeader(PrintStreamPrinter printer)
protected String createPrintText(int level, String tag, String msg)
level
- log leveltag
- log tagmsg
- log contentpublic final String getLogFilePath()
Override this method is not really recommended; consider using constructor instead.
public void close()
close
in interface Closeable
close
in interface AutoCloseable