Package org.h2.message
Class TraceSystem
- java.lang.Object
-
- org.h2.message.TraceSystem
-
- All Implemented Interfaces:
TraceWriter
public class TraceSystem extends java.lang.Object implements TraceWriter
The trace mechanism is the logging facility of this database. There is usually one trace system per database. It is called 'trace' because the term 'log' is already used in the database domain and means 'transaction log'. It is possible to write after close was called, but that means for each write the file will be opened and closed again (which is slower).
-
-
Field Summary
Fields Modifier and Type Field Description static intADAPTERThis trace level means all type of messages should be written, but instead of using the trace file the messages should be written to SLF4J.private static intCHECK_SIZE_EACH_WRITESprivate intcheckSizeStarts at -1 so that we check the file size immediately upon open.private booleanclosedprivate java.text.SimpleDateFormatdateFormatstatic intDEBUGThis trace level means all type of messages should be written.private static intDEFAULT_MAX_FILE_SIZEThe default maximum trace file size.static intDEFAULT_TRACE_LEVEL_FILEThe default level for file trace messages.static intDEFAULT_TRACE_LEVEL_SYSTEM_OUTThe default level for system out trace messages.static intERRORThis trace level means only errors should be written.private java.lang.StringfileNameprivate java.io.WriterfileWriterstatic intINFOThis trace level means errors and informational messages should be written.private intlevelFileprivate intlevelMaxprivate intlevelSystemOutprivate intmaxFileSizestatic intOFFThis trace level means nothing should be written.static intPARENTThe parent trace level should be used.private java.io.PrintWriterprintWriterprivate java.io.PrintStreamsysOutprivate java.util.concurrent.atomic.AtomicReferenceArray<Trace>tracesprivate TraceWriterwriterprivate booleanwritingErrorLogged
-
Constructor Summary
Constructors Constructor Description TraceSystem(java.lang.String fileName)Create a new trace system object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the writers, and the files if required.private voidcloseWriter()private java.lang.Stringformat(java.lang.String module, java.lang.String s)intgetLevelFile()TracegetTrace(int moduleId)Get or create a trace object for this module id.TracegetTrace(java.lang.String module)Create a trace object for this module.booleanisEnabled(int level)Check the given trace / log level is enabled.private voidlogWritingError(java.lang.Exception e)private booleanopenWriter()voidsetFileName(java.lang.String name)Set the trace file name.voidsetLevelFile(int level)Set the file trace level.voidsetLevelSystemOut(int level)Set the trace level to use for System.outvoidsetMaxFileSize(int max)Set the maximum trace file size in bytes.voidsetName(java.lang.String name)Set the name of the database or trace object.voidsetSysOut(java.io.PrintStream out)Set the print stream to use instead of System.out.private voidupdateLevel()voidwrite(int level, int moduleId, java.lang.String s, java.lang.Throwable t)Write a message.voidwrite(int level, java.lang.String module, java.lang.String s, java.lang.Throwable t)Write a message.private voidwriteFile(java.lang.String s, java.lang.Throwable t)
-
-
-
Field Detail
-
PARENT
public static final int PARENT
The parent trace level should be used.- See Also:
- Constant Field Values
-
OFF
public static final int OFF
This trace level means nothing should be written.- See Also:
- Constant Field Values
-
ERROR
public static final int ERROR
This trace level means only errors should be written.- See Also:
- Constant Field Values
-
INFO
public static final int INFO
This trace level means errors and informational messages should be written.- See Also:
- Constant Field Values
-
DEBUG
public static final int DEBUG
This trace level means all type of messages should be written.- See Also:
- Constant Field Values
-
ADAPTER
public static final int ADAPTER
This trace level means all type of messages should be written, but instead of using the trace file the messages should be written to SLF4J.- See Also:
- Constant Field Values
-
DEFAULT_TRACE_LEVEL_SYSTEM_OUT
public static final int DEFAULT_TRACE_LEVEL_SYSTEM_OUT
The default level for system out trace messages.- See Also:
- Constant Field Values
-
DEFAULT_TRACE_LEVEL_FILE
public static final int DEFAULT_TRACE_LEVEL_FILE
The default level for file trace messages.- See Also:
- Constant Field Values
-
DEFAULT_MAX_FILE_SIZE
private static final int DEFAULT_MAX_FILE_SIZE
The default maximum trace file size. It is currently 64 MB. Additionally, there could be a .old file of the same size.- See Also:
- Constant Field Values
-
CHECK_SIZE_EACH_WRITES
private static final int CHECK_SIZE_EACH_WRITES
- See Also:
- Constant Field Values
-
levelSystemOut
private int levelSystemOut
-
levelFile
private int levelFile
-
levelMax
private int levelMax
-
maxFileSize
private int maxFileSize
-
fileName
private java.lang.String fileName
-
traces
private final java.util.concurrent.atomic.AtomicReferenceArray<Trace> traces
-
dateFormat
private java.text.SimpleDateFormat dateFormat
-
fileWriter
private java.io.Writer fileWriter
-
printWriter
private java.io.PrintWriter printWriter
-
checkSize
private int checkSize
Starts at -1 so that we check the file size immediately upon open. This Can be important if we open and close the trace file without managing to have written CHECK_SIZE_EACH_WRITES bytes each time.
-
closed
private boolean closed
-
writingErrorLogged
private boolean writingErrorLogged
-
writer
private TraceWriter writer
-
sysOut
private java.io.PrintStream sysOut
-
-
Method Detail
-
updateLevel
private void updateLevel()
-
setSysOut
public void setSysOut(java.io.PrintStream out)
Set the print stream to use instead of System.out.- Parameters:
out- the new print stream
-
getTrace
public Trace getTrace(int moduleId)
Get or create a trace object for this module id. Trace modules with id are cached.- Parameters:
moduleId- module id- Returns:
- the trace object
-
getTrace
public Trace getTrace(java.lang.String module)
Create a trace object for this module. Trace modules with names are not cached.- Parameters:
module- the module name- Returns:
- the trace object
-
isEnabled
public boolean isEnabled(int level)
Description copied from interface:TraceWriterCheck the given trace / log level is enabled.- Specified by:
isEnabledin interfaceTraceWriter- Parameters:
level- the level- Returns:
- true if the level is enabled
-
setFileName
public void setFileName(java.lang.String name)
Set the trace file name.- Parameters:
name- the file name
-
setMaxFileSize
public void setMaxFileSize(int max)
Set the maximum trace file size in bytes.- Parameters:
max- the maximum size
-
setLevelSystemOut
public void setLevelSystemOut(int level)
Set the trace level to use for System.out- Parameters:
level- the new level
-
setLevelFile
public void setLevelFile(int level)
Set the file trace level.- Parameters:
level- the new level
-
getLevelFile
public int getLevelFile()
-
format
private java.lang.String format(java.lang.String module, java.lang.String s)
-
write
public void write(int level, int moduleId, java.lang.String s, java.lang.Throwable t)Description copied from interface:TraceWriterWrite a message.- Specified by:
writein interfaceTraceWriter- Parameters:
level- the trace levelmoduleId- the id of the modules- the messaget- the exception (may be null)
-
write
public void write(int level, java.lang.String module, java.lang.String s, java.lang.Throwable t)Description copied from interface:TraceWriterWrite a message.- Specified by:
writein interfaceTraceWriter- Parameters:
level- the trace levelmodule- the name of the modules- the messaget- the exception (may be null)
-
writeFile
private void writeFile(java.lang.String s, java.lang.Throwable t)
-
logWritingError
private void logWritingError(java.lang.Exception e)
-
openWriter
private boolean openWriter()
-
closeWriter
private void closeWriter()
-
close
public void close()
Close the writers, and the files if required. It is still possible to write after closing, however after each write the file is closed again (slowing down tracing).
-
setName
public void setName(java.lang.String name)
Description copied from interface:TraceWriterSet the name of the database or trace object.- Specified by:
setNamein interfaceTraceWriter- Parameters:
name- the new name
-
-