Package com.databricks.jdbc.log

## Class JulLogger

- java.lang.Object
- - com.databricks.jdbc.log.JulLogger

All Implemented Interfaces:
  `JdbcLogger`

    public class JulLogger
    extends Object
    implements 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
`static String` `DATABRICKS_LOG_FILE`
`protected static boolean` `isLoggerInitialized`
`static String` `JAVA_UTIL_LOGGING_CONFIG_FILE`
`protected Logger` `logger`
`static String` `PARENT_CLASS_PREFIX`
`static String` `STDOUT`

### Constructor Summary

Constructors
`JulLogger​(String name)` Constructs a new `JulLogger` object with the specified name.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `debug​(String message)`
`void` `error​(String message)`
`void` `error​(String message, Throwable throwable)`
`protected static String[]` `getCaller()` Retrieves the class name and method name of the caller that initiated the logging request.
`protected static String` `getLogPattern​(String logDir)` Generates the log file pattern based on the provided log directory.
`void` `info​(String message)`
`static void` `initLogger​(Level level, String logDir, int logFileSizeBytes, int logFileCount)` Initializes the logger with the specified configuration.
`void` `trace​(String message)`
`void` `warn​(String message)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### STDOUT

    public static final String STDOUT

See Also:
  Constant Field Values

#### PARENT_CLASS_PREFIX

    public static final String PARENT_CLASS_PREFIX

See Also:
  Constant Field Values

#### DATABRICKS_LOG_FILE

    public static final String DATABRICKS_LOG_FILE

See Also:
  Constant Field Values

#### JAVA_UTIL_LOGGING_CONFIG_FILE

    public static final String JAVA_UTIL_LOGGING_CONFIG_FILE

See Also:
  Constant Field Values

#### logger

    protected Logger logger

#### isLoggerInitialized

    protected static volatile boolean isLoggerInitialized

### Constructor Detail

#### JulLogger

    public JulLogger​(String name)

Constructs a new `JulLogger` object with the specified name.

### Method Detail

#### trace

    public void trace​(String message)

Specified by:
  `trace` in interface `JdbcLogger`

#### debug

    public void debug​(String message)

Specified by:
  `debug` in interface `JdbcLogger`

#### info

    public void info​(String message)

Specified by:
  `info` in interface `JdbcLogger`

#### warn

    public void warn​(String message)

Specified by:
  `warn` in interface `JdbcLogger`

#### error

    public void error​(String message)

Specified by:
  `error` in interface `JdbcLogger`

#### error

    public void error​(String message,
                      Throwable throwable)

Specified by:
  `error` in interface `JdbcLogger`

#### 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 level
  `logDir` - the directory for log files or `STDOUT` for console output
  `logFileSizeBytes` - the maximum size of a single log file in bytes
  `logFileCount` - the number of log files to rotate
Throws:
  `IOException` - if an I/O error occurs

#### getCaller

    protected static String[] 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:

1. 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).
2. 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

    protected static String getLogPattern​(String logDir)

Generates the log file pattern based on the provided log directory. If the log directory is specified as "STDOUT", logging will be directed to the console. Otherwise, it ensures the directory exists and resolves the log file path within it.