Implementation:Vespa engine Vespa VespaLogHandler Constructor
VespaLogHandler Constructor
API Signature
VespaLogHandler(LogTarget logTarget, LevelControllerRepo levelControllerRepo,
String serviceName, String applicationPrefix)
Source Location
- File: vespalog/src/main/java/com/yahoo/log/VespaLogHandler.java
- Lines: L51-59
- Class:
class VespaLogHandler extends StreamHandler - Package:
com.yahoo.log
Description
The VespaLogHandler constructor assembles the core logging handler that replaces the default JUL handlers. It wires together the log target (output destination), level controller repository (per-component level checking), service metadata, and the reject filter. After construction, the initialize() method sets up the VespaFormatter and configures the handler for use.
Key Fields
| Field | Type | Purpose |
|---|---|---|
logTarget |
LogTarget |
Output destination (file, stderr, etc.) that provides an OutputStream on each open() call
|
serviceName |
String |
The Vespa service identity (e.g., "searchnode", "configserver") included in every log line
|
appPrefix |
String |
Application prefix prepended to component names in the control file and log output |
repo |
LevelControllerRepo |
Repository that provides per-component LevelController instances for shouldLog() checks
|
logRejectFilter |
RejectFilter |
Content-based filter that drops known-useless log messages |
Parameters
| Parameter | Type | Description |
|---|---|---|
logTarget |
LogTarget |
The log output target. Created from the VESPA_LOG_TARGET configuration value. Supports file descriptors (fd:2), file paths (file:/path), and stdout.
|
levelControllerRepo |
LevelControllerRepo |
The level controller repository, either a VespaLevelControllerRepo (memory-mapped) or DefaultLevelControllerRepo (static levels).
|
serviceName |
String |
The Vespa service name (from VESPA_SERVICE_NAME). Used in the VespaFormatter to populate the service field of each log line.
|
applicationPrefix |
String |
The application prefix (typically the program name). Used as the component prefix in log output and control file entries. |
Constructor Source
VespaLogHandler(LogTarget logTarget, LevelControllerRepo levelControllerRepo,
String serviceName, String applicationPrefix) {
this.logTarget = logTarget;
this.serviceName = serviceName;
this.appPrefix = applicationPrefix;
this.repo = levelControllerRepo;
this.logRejectFilter = RejectFilter.createDefaultRejectFilter();
initialize();
}
Initialization Sequence
Step 1: Store Dependencies
this.logTarget = logTarget;
this.serviceName = serviceName;
this.appPrefix = applicationPrefix;
this.repo = levelControllerRepo;
All four constructor parameters are stored as instance fields. These are used during the publish() call path.
Step 2: Create the Reject Filter
this.logRejectFilter = RejectFilter.createDefaultRejectFilter();
The RejectFilter is a content-based filter that examines log message text and drops messages matching known-useless patterns. The default filter is created via a factory method that includes patterns for common noisy messages. This filter is applied after level checking, as an additional layer of noise reduction.
Step 3: Initialize the Handler
initialize();
The initialize() method (not shown in the constructor) performs the following setup:
- Creates a
VespaFormatterwith the service name and application prefix. - Sets the formatter on this handler via
setFormatter(). - Sets the handler level to
ALLso that level filtering is handled by theLevelControllerrather than the JUL framework.
Level Reduction Map
The handler also maintains a level reduction map for noisy third-party loggers. This is a static mapping that reduces the effective log level for specific logger name prefixes:
// Conceptual level reduction:
// "org.eclipse.jetty" -> reduce INFO to DEBUG
// "org.apache.aries.spifly" -> reduce INFO to DEBUG
The possiblyReduceLogLevel(String loggerName, Level level) method checks if the logger name matches any prefix in the reduction map. If it does, the level is reduced (e.g., INFO becomes DEBUG), effectively silencing these loggers under default configuration.
The getLevelControl Method
When publish() needs to check if a log record should be output, it calls:
LevelController ctrl = getLevelControl(loggerName);
This method:
- Looks up the logger name in the
LevelControllerRepo. - If a per-component entry exists in the control file, returns its
LevelController. - If no entry exists, registers the component in the control file and returns a new controller initialized with default levels.
Usage Context
The constructor is called from LogSetup.initInternal():
// Inside LogSetup.initInternal():
LogTarget target = LogTarget.createLogTarget(logTargetString);
LevelControllerRepo repo = new VespaLevelControllerRepo(logControlFile, logLevel, programName);
VespaLogHandler handler = new VespaLogHandler(target, repo, serviceName, programName);
// Install on root logger
Logger rootLogger = Logger.getLogger("");
for (Handler h : rootLogger.getHandlers()) {
rootLogger.removeHandler(h);
}
rootLogger.addHandler(handler);
rootLogger.setLevel(Level.ALL);
Implements Principle
Related Implementations
- LogSetup.initVespaLogging -- Resolves configuration and triggers handler construction
- VespaLevelControllerRepo Constructor -- Creates the level controller repo passed to this constructor
- VespaLogHandler.publish -- The method called on each log record after the handler is installed
- VespaFormatter.format -- The formatter used to produce tab-delimited output