public final class DebugFile extends Object
Write execution traces to Log4j2, a set of text files (one per thread) or STDOUT
DebugFile will decide where to write debug traces with following algorithm:
knowgate.debugfile
exists this will be assumed to be the absolute path to the properties file that tells whether Log4j2, files, or stdout must be used for output.knowgate.debugfile
is not set then DebugFile will try to read /etc/debugfile.conf
on *nix or C:\\Windows\System32\drivers\etc\debugfile.conf on Windows
debugfile.conf
is not found the DebugFile will use the package resource at com/knowgate/debug/debugfile.conf
The default behavior is use a Log4j2 configuration provided by the client application for com.knowgate.debug.DebugFile.class
This configuration file must be placed in the CLASSPATH as described in Log4j 2.c configuration.
A sample log4j2.xml file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug" strict="true" name="XMLConfigTest" packages="org.apache.logging.log4j.test">
<Properties>
<Property name="filename">/var/log/knowgate/debug.log</Property>
</Properties>
<Appenders>
<Appender type="File" name="File" fileName="${filename}">
<Layout type="PatternLayout">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</Layout>
</Appender>
<Appender type="List" name="List">
</Appender>
</Appenders>
<Loggers>
<Logger name="com.knowgate.debug" level="debug" additivity="false">
<AppenderRef ref="File"/>
</Logger>
<Root level="trace">
<AppenderRef ref="List"/>
</Root>
</Loggers>
</Configuration>
To avoid using Log4j2 create a properties file at /etc/debugfile.conf on *nix or C:\Windows\System32\drivers\etc\debugfile.conf on Windows.
The file must contain the following properties:
# Accepted values are file stdout and log4j
sink=file
# Only applies if sink is file or stdout otherwise debug is controlled by Log4J
debug=true
# Only applies if sink is file
debugdir_win32=C:\\TEMP\\Debug\\
debugdir_linux=/var/log/knowgate/
Modifier and Type | Field and Description |
---|---|
static short |
DUMP_TO_FILE |
static short |
DUMP_TO_LOG4J |
static short |
DUMP_TO_STDOUT |
static short |
dumpTo
One of DUMP_TO_LOG4J, DUMP_TO_FILE or DUMP_TO_STDOUT constants
|
static boolean |
trace
Activate/Deactivate debug output
|
Constructor and Description |
---|
DebugFile() |
Modifier and Type | Method and Description |
---|---|
void |
debug(String str)
This method is just an alias for DebugFile.writeln
|
void |
debug(String str,
Exception xcpt)
Write message and stack trace for an exception to debug output
|
static void |
decIdent()
Decrement indentation level
|
static void |
envinfo()
Write environment information to debug output
|
static String |
getConfFile()
Get absolute path of the debugfile.conf file
|
static String |
getFile(long threadId)
Get debug file path Read Java environment variable knowgate.debugdir to
get the directory where javatrc.txt files are generated.
|
static void |
incIdent()
Increment indentation level Maximum indentation level is 80, after
reaching that limit Indentation is automatically set to zero
|
static void |
main(String[] argv) |
static void |
refresh()
Refresh DebugFile and here on use changes made in configuration.
|
static void |
setConfFile(String confFilePath)
Set absolute path to debugfile properties file
|
static void |
setFile(String sDebugFilePath)
Set debug file path
|
static void |
write(char[] str)
Write trace
|
static void |
write(String str)
Write trace
|
static void |
writeln(char[] str)
Write trace and append line feed
|
static void |
writeln(String str)
Write trace and append line feed
|
static void |
writeStackTrace(Throwable t)
Write stack trace for an exception to debug output
|
public static final short DUMP_TO_FILE
public static final short DUMP_TO_STDOUT
public static final short DUMP_TO_LOG4J
public static short dumpTo
public static boolean trace
public static String getConfFile()
Get absolute path of the debugfile.conf file
This is not the Log4j2 file at the appender but the properties files used to set whether DebugFile will use Log4j2, stdout or its own set of output files.
By default is /etc/debugfile.conf on *nix and C:\Windows\System32\drivers\etc\debugfile.conf on Windows.
public static void setConfFile(String confFilePath)
Set absolute path to debugfile properties file
confFilePath
- Stringpublic static void refresh()
Refresh DebugFile and here on use changes made in configuration.
public static void setFile(String sDebugFilePath)
sDebugFilePath
- Full path to file where debug traces will be written including directory and file namepublic static String getFile(long threadId)
threadId
- long Files are generated per thread, so inform which one is dumping the tracespublic static void incIdent()
public static void decIdent()
public static void write(char[] str)
Write trace
If setFile() has not been called, traces are written to /vagrant/tmp/ on UNIX systems or C:\Temp\Debug on Windowsstr
- Characters to be writtenpublic static void write(String str)
Write trace
Traces are written to /tmp/javatrc.txt on UNIX systems or C:\TEMP\Debug\javatrc.txt on Windowsstr
- String to be writtenpublic static void writeln(String str)
Write trace and append line feed
str
- String to be writtenpublic static void writeln(char[] str)
Write trace and append line feed
str
- String to be writtenpublic static void writeStackTrace(Throwable t)
Write stack trace for an exception to debug output
t
- Throwablepublic void debug(String str)
This method is just an alias for DebugFile.writeln
str
- Stringpublic void debug(String str, Exception xcpt)
Write message and stack trace for an exception to debug output
str
- String Messagexcpt
- Exceptionpublic static void envinfo() throws AccessControlException
Write environment information to debug output
AccessControlException
Copyright © 2001–2019 KnowGate. All rights reserved.