Class JulLogger
java.lang.Object
com.databricks.jdbc.log.JulLogger
- All Implemented Interfaces:
JdbcLogger
The
JulLogger class provides an implementation of the JdbcLogger interface using
the Java Util Logging (JUL) framework. It supports logging messages at different levels such as
trace, debug, info, warn, and error, both with and without associated Throwable objects.
This class also includes a static method to initialize the logger with custom configurations such as log level, log directory, log file size, and log file count. It supports logging to both the console and file system based on the provided configuration.
Log messages include the name of the class and method from where the logging request was made, providing a clear context for the log messages. This is achieved by analyzing the stack trace to find the caller information.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidvoidvoidvoidprotected static String[]Retrieves the class name and method name of the caller that initiated the logging request.protected static StringgetLogPattern(String logDir) Generates the log file pattern based on the provided log directory.voidvoidstatic voidinitLogger(Level level, String logDir, int logFileSizeBytes, int logFileCount) Initializes the logger with the specified configuration.voidvoidvoidvoid
-
Field Details
-
STDOUT
- See Also:
-
PARENT_CLASS_PREFIX
-
DRIVER_CLASS_PREFIX
-
DATABRICKS_LOG_FILE
- See Also:
-
JAVA_UTIL_LOGGING_CONFIG_FILE
- See Also:
-
logger
-
isLoggerInitialized
protected static volatile boolean isLoggerInitialized
-
-
Constructor Details
-
JulLogger
Constructs a newJulLoggerobject with the specified name.
-
-
Method Details
-
trace
- Specified by:
tracein interfaceJdbcLogger
-
trace
- Specified by:
tracein interfaceJdbcLogger
-
debug
- Specified by:
debugin interfaceJdbcLogger
-
debug
- Specified by:
debugin interfaceJdbcLogger
-
info
- Specified by:
infoin interfaceJdbcLogger
-
info
- Specified by:
infoin interfaceJdbcLogger
-
warn
- Specified by:
warnin interfaceJdbcLogger
-
warn
- Specified by:
warnin interfaceJdbcLogger
-
error
- Specified by:
errorin interfaceJdbcLogger
-
error
- Specified by:
errorin interfaceJdbcLogger
-
error
- Specified by:
errorin interfaceJdbcLogger
-
error
- Specified by:
errorin interfaceJdbcLogger
-
initLogger
public static void initLogger(Level level, String logDir, int logFileSizeBytes, int logFileCount) throws IOException Initializes the logger with the specified configuration. This method is synchronized to prevent concurrent modifications to the logger configuration.- Parameters:
level- the log levellogDir- the directory for log files orSTDOUTfor console outputlogFileSizeBytes- the maximum size of a single log file in byteslogFileCount- the number of log files to rotate- Throws:
IOException- if an I/O error occurs
-
getCaller
Retrieves the class name and method name of the caller that initiated the logging request. This method navigates the stack trace to find the first method outside the known logging methods, providing the context from where the log was called. This is particularly useful for including in log messages to identify the source of the log entry.The method uses a two-step filtering process on the stack trace:
- It first drops stack trace elements until it finds one whose method name is a known logging method (e.g., trace, debug, info, warn, error).
- Then, it continues to drop elements until it finds the first method not in the set of logging methods, which is considered the caller.
-
getLogPattern
-