Skip to content

Implement Refined JUL Logging Strategy with ERROR/PERFORMANCE Prefixes #34

Description

@simbo1905

Problem Statement

Currently, our JUL logging implementation doesn't follow Oracle's official guidelines and lacks compatibility considerations for teams using SLF4J/Log4j bridges and cloud log filtering.

Proposed Solution

Implement a refined JUL logging strategy that aligns with Oracle's official documentation while providing practical compatibility for teams expecting traditional ERROR level messages.

Key Requirements

1. ERROR Prefix for SEVERE Level

IMPORTANT: Since JUL is widely bridged to SLF4J and teams often filter on ERROR strings (not SEVERE), prefix SEVERE level messages with "ERROR:" for cloud log monitoring compatibility.

LOG.severe(() -> "ERROR: Remote references disabled but computeIfAbsent called for: " + key);

Apply ERROR prefix only for:

  • Logging before throwing exceptions
  • Clear validation issues
  • Cases where SLF4J/Log4j users would typically log at error level
  • Messages that cloud log filters should catch for monitoring

2. Performance Warning Prefix

Use consistent "PERFORMANCE WARNING:" prefix for potential performance issues (which Oracle guidelines specify should use FINE level):

// Oracle guidelines: FINE (500) is appropriate for "potential performance problems"
LOG.fine(() -> "PERFORMANCE WARNING: Validation stack processing " + count + " items exceeds recommended threshold of " + threshold);

3. Oracle JUL Level Hierarchy

Follow Oracle's official target-audience-based hierarchy:

  • SEVERE (1000): Serious failures preventing normal execution + ERROR prefix when appropriate
  • WARNING (900): Potential problems for end users/system managers
  • INFO (800): Reasonably significant messages for end users/administrators (use sparingly)
  • CONFIG (700): Static configuration information for debugging setup issues
  • FINE (500): Developer debugging info, minor recoverable failures, performance warnings
  • FINER (400): Detailed tracing, method entry/exit, exception throwing
  • FINEST (300): Maximum detail debugging, data structures, wire protocol data

4. Lambda-Based Logging Only

ALL logging must use lambda expressions to ensure zero runtime overhead when log levels are disabled. The JVM optimizes away unused lambda branches automatically.

Implementation Tasks

  • Audit existing log statements and map to appropriate JUL levels
  • Add "ERROR:" prefix to SEVERE level messages that warrant cloud monitoring
  • Add "PERFORMANCE WARNING:" prefix to FINE level performance issue messages
  • Convert all logging to lambda expressions for zero runtime overhead
  • Use hierarchical logger naming (fully-qualified class names)
  • Add CONFIG level logging for static configuration reporting
  • Document logging strategy in README or developer guide

Examples of Level Usage

// SEVERE with ERROR prefix - prevents normal execution
LOG.severe(() -> "ERROR: Failed to compile JSON schema: " + schemaUri);

// WARNING - recoverable issue
LOG.warning(() -> "Deprecated schema version detected, using compatibility mode");

// INFO - significant but not noisy
LOG.info(() -> "JSON schema validator initialized with " + schemaCount + " schemas");

// CONFIG - configuration details
LOG.config(() -> "Validation features enabled: " + Arrays.toString(enabledFeatures));

// FINE - developer debugging and performance warnings  
LOG.fine(() -> "PERFORMANCE WARNING: Deep recursion detected at depth " + depth);
LOG.fine(() -> "Schema cache miss for: " + schemaId);

// FINER - detailed tracing
LOG.finer(() -> "Entering validation method for schema: " + schemaType);

// FINEST - maximum detail (JVM optimizes away when disabled)
LOG.finest(() -> "Raw JSON data: " + jsonData);
LOG.finest(() -> "Expensive debug info: " + computeExpensiveDebugString());

Rationale

This approach provides:

  1. Oracle compliance: Follows official JUL documentation
  2. Practical compatibility: ERROR prefix ensures cloud log monitoring works
  3. Performance awareness: Consistent PERFORMANCE WARNING prefix for threshold issues
  4. Zero runtime overhead: Lambda expressions eliminate performance impact of disabled logging
  5. Developer productivity: Clear level hierarchy for different debugging needs
  6. Library best practices: Conservative logging appropriate for library consumers

Acceptance Criteria

  • All existing log statements reviewed and properly leveled
  • ERROR prefix applied to appropriate SEVERE messages
  • PERFORMANCE WARNING prefix used for performance threshold issues
  • ALL logging converted to lambda expressions for zero runtime overhead when log levels disabled
  • Hierarchical logger naming implemented (fully-qualified class names)
  • Documentation updated with logging strategy
  • Examples provided for each logging level
  • Lambda-based logging enforced to ensure JVM optimizes away unused branches automatically

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions