Top Description Fields Constructors Methods
org.h2.message

public Class TraceSystem

extends Object
implements TraceWriter
Class Inheritance
All Implemented Interfaces
org.h2.message.TraceWriter
Static Imports
java.time.temporal.ChronoField.HOUR_OF_DAY, .ChronoField.MINUTE_OF_HOUR, .ChronoField.NANO_OF_SECOND, .ChronoField.SECOND_OF_MINUTE

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

Modifier and TypeField and Description
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.

private static final int
private int
checkSize

Starts at -1 so that we check the file size immediately upon open.

private boolean
private static DateTimeFormatter
public static final int
DEBUG

This trace level means all type of messages should be written.

private static final int
DEFAULT_MAX_FILE_SIZE

The default maximum trace file size.

public static final int
DEFAULT_TRACE_LEVEL_FILE

The default level for file trace messages.

public static final int
DEFAULT_TRACE_LEVEL_SYSTEM_OUT

The default level for system out trace messages.

public static final int
ERROR

This trace level means only errors should be written.

private String
private Writer
public static final int
INFO

This trace level means errors and informational messages should be written.

private int
private int
private int
private int
public static final int
OFF

This trace level means nothing should be written.

public static final int
PARENT

The parent trace level should be used.

private PrintWriter
private PrintStream
private final AtomicReferenceArray<Trace>
private TraceWriter
private boolean

Constructor Summary

AccessConstructor and Description
public
TraceSystem(String
the file name
fileName
)

Create a new trace system object.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Close the writers, and the files if required.

private synchronized void
private static String
format(String module, String s)

public int
public Trace

Returns:

the trace object
getTrace
(int
module id
moduleId
)

Get or create a trace object for this module id. Trace modules with id are cached.

public Trace

Returns:

the trace object
getTrace
(String
the module name
module
)

Create a trace object for this module.

private static DateTimeFormatter
public boolean
isEnabled(int
the level
level
)

Implements org.h2.message.TraceWriter.isEnabled.

Check the given trace / log level is enabled.

private void
private boolean
public void
setFileName(String
the file name
name
)

Set the trace file name.

public void
setLevelFile(int
the new level
level
)

Set the file trace level.

public void
setLevelSystemOut(int
the new level
level
)

Set the trace level to use for System.out

public void
setMaxFileSize(int
the maximum size
max
)

Set the maximum trace file size in bytes.

public void
setName(String
the new name
name
)

Implements org.h2.message.TraceWriter.setName.

Set the name of the database or trace object.

public void
setSysOut(PrintStream
the new print stream
out
)

Set the print stream to use instead of System.out.

private void
public void
write(int
the trace level
level
,
int
the id of the module
moduleId
,
String
the message
s
,
Throwable
the exception (may be null)
t
)

Implements org.h2.message.TraceWriter.write.

Write a message.

public void
write(int
the trace level
level
,
String
the name of the module
module
,
String
the message
s
,
Throwable
the exception (may be null)
t
)

Implements org.h2.message.TraceWriter.write.

Write a message.

private synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ADAPTERback to summary
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.

CHECK_SIZE_EACH_WRITESback to summary
private static final int CHECK_SIZE_EACH_WRITES
checkSizeback to summary
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.

closedback to summary
private boolean closed
DATE_TIME_FORMATTERback to summary
private static DateTimeFormatter DATE_TIME_FORMATTER
DEBUGback to summary
public static final int DEBUG

This trace level means all type of messages should be written.

DEFAULT_MAX_FILE_SIZEback to summary
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.

DEFAULT_TRACE_LEVEL_FILEback to summary
public static final int DEFAULT_TRACE_LEVEL_FILE

The default level for file trace messages.

DEFAULT_TRACE_LEVEL_SYSTEM_OUTback to summary
public static final int DEFAULT_TRACE_LEVEL_SYSTEM_OUT

The default level for system out trace messages.

ERRORback to summary
public static final int ERROR

This trace level means only errors should be written.

fileNameback to summary
private String fileName
fileWriterback to summary
private Writer fileWriter
INFOback to summary
public static final int INFO

This trace level means errors and informational messages should be written.

levelFileback to summary
private int levelFile
levelMaxback to summary
private int levelMax
levelSystemOutback to summary
private int levelSystemOut
maxFileSizeback to summary
private int maxFileSize
OFFback to summary
public static final int OFF

This trace level means nothing should be written.

PARENTback to summary
public static final int PARENT

The parent trace level should be used.

printWriterback to summary
private PrintWriter printWriter
sysOutback to summary
private PrintStream sysOut
tracesback to summary
private final AtomicReferenceArray<Trace> traces
writerback to summary
private TraceWriter writer
writingErrorLoggedback to summary
private boolean writingErrorLogged

Constructor Detail

TraceSystemback to summary
public TraceSystem(String fileName)

Create a new trace system object.

Parameters
fileName:String

the file name

Method Detail

closeback to summary
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).

closeWriterback to summary
private synchronized void closeWriter()
formatback to summary
private static String format(String module, String s)
getLevelFileback to summary
public int getLevelFile()
getTraceback to summary
public Trace getTrace(int moduleId)

Get or create a trace object for this module id. Trace modules with id are cached.

Parameters
moduleId:int

module id

Returns:Trace

the trace object

getTraceback to summary
public Trace getTrace(String module)

Create a trace object for this module. Trace modules with names are not cached.

Parameters
module:String

the module name

Returns:Trace

the trace object

initTimeFormatterback to summary
private static DateTimeFormatter initTimeFormatter()
isEnabledback to summary
public boolean isEnabled(int level)

Implements org.h2.message.TraceWriter.isEnabled.

Doc from org.h2.message.TraceWriter.isEnabled.

Check the given trace / log level is enabled.

Parameters
level:int

the level

Returns:boolean

true if the level is enabled

Annotations
@Override
logWritingErrorback to summary
private void logWritingError(Exception e)
openWriterback to summary
private boolean openWriter()
setFileNameback to summary
public void setFileName(String name)

Set the trace file name.

Parameters
name:String

the file name

setLevelFileback to summary
public void setLevelFile(int level)

Set the file trace level.

Parameters
level:int

the new level

setLevelSystemOutback to summary
public void setLevelSystemOut(int level)

Set the trace level to use for System.out

Parameters
level:int

the new level

setMaxFileSizeback to summary
public void setMaxFileSize(int max)

Set the maximum trace file size in bytes.

Parameters
max:int

the maximum size

setNameback to summary
public void setName(String name)

Implements org.h2.message.TraceWriter.setName.

Doc from org.h2.message.TraceWriter.setName.

Set the name of the database or trace object.

Parameters
name:String

the new name

Annotations
@Override
setSysOutback to summary
public void setSysOut(PrintStream out)

Set the print stream to use instead of System.out.

Parameters
out:PrintStream

the new print stream

updateLevelback to summary
private void updateLevel()
writeback to summary
public void write(int level, int moduleId, String s, Throwable t)

Implements org.h2.message.TraceWriter.write.

Doc from org.h2.message.TraceWriter.write.

Write a message.

Parameters
level:int

the trace level

moduleId:int

the id of the module

s:String

the message

t:Throwable

the exception (may be null)

Annotations
@Override
writeback to summary
public void write(int level, String module, String s, Throwable t)

Implements org.h2.message.TraceWriter.write.

Doc from org.h2.message.TraceWriter.write.

Write a message.

Parameters
level:int

the trace level

module:String

the name of the module

s:String

the message

t:Throwable

the exception (may be null)

Annotations
@Override
writeFileback to summary
private synchronized void writeFile(String s, Throwable t)