Skip to content

Add lightweight karaf-logging service and use it in apache-karaf-light - #2949

Merged
jbonofre merged 7 commits into
apache:mainfrom
jbonofre:karaf-logging
Nov 17, 2026
Merged

jbonofre merged 7 commits into
apache:mainfrom
jbonofre:karaf-logging

Conversation

@jbonofre

@jbonofre jbonofre commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Description

This PR introduces a lightweight logging service org.apache.karaf.services.logging intended as a simple replacement for Pax Logging in the apache-karaf-light distribution.

Key Highlights

  • Simple Backend: Directly delegates logging to standard Java SE java.util.logging (JUL), eliminating heavy logging framework dependencies in lightweight environments.
  • Supported APIs:
    • OSGi LogService R7 (org.osgi.service.log 1.5) with bundle-specific context and LogReaderService.
    • SLF4J 2.x and 1.7.x via embedded slf4j-jdk14 and backward-compatible StaticLoggerBinder.
    • Commons Logging 1.2 via embedded jcl-over-slf4j.
  • Framework Features:
    • Added framework-light and static-framework-light features to feature definitions.
    • Updated karaf-maven-plugin's AssemblyMojo to support the light frameworks.
  • Apache Karaf Light Distribution:
    • Configured apache-karaf-light to use framework-light with org.apache.karaf.services.logging.
    • Blacklisted pax-logging bundles so no Pax Logging artifacts are pulled or packaged.
    • Added default configuration file etc/org.apache.karaf.logging.cfg.
  • Logging behavior:
    • karaf.log is rolled over by size (file.maxSize, default 10MB), keeping file.maxBackupIndex backups (default 5) as karaf.log.1, karaf.log.2, ... When karaf.log can't be renamed (on Windows, when another process keeps it open), it's copied and truncated. Like Pax Logging, the service resets java.util.logging on startup, which closes the Karaf Main bootstrap log handlers.
    • Console output is disabled by default (console = ${karaf.log.console:-OFF}), as in the standard distribution.
    • Logger specific levels (logger.<name> = <level>) are applied dynamically through Configuration Admin. Deleting etc/org.apache.karaf.logging.cfg restores the default configuration.
    • Like Pax Logging, the LogService logger is named after the calling bundle symbolic name.
  • Karaf integration:
    • dev:dump-create includes the Karaf logging service file (it no longer creates an empty org.ops4j.pax.logging configuration to look for the Pax Logging files).
    • instance:create uses etc/org.apache.karaf.logging.cfg instead of etc/org.ops4j.pax.logging.cfg when the root instance uses the Karaf logging service.

Notes

  • As the log feature requires Pax Logging, the log:* commands and the JMX LogMBean are not available in apache-karaf-light: log levels are changed in etc/org.apache.karaf.logging.cfg (or with config:* commands). This is documented in the user guide (log.adoc).

Verification

  • Unit tests in services/logging, diagnostic/core and instance pass cleanly.
  • Apache RAT license check passes with 0 issues.
  • apache-karaf-light package and runtime boot verified: starts all bundles cleanly, logs properly formatted into data/log/karaf.log, and shuts down with zero exceptions. dev:dump-create and instance:create verified on the light distribution.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Test Results

  795 files  + 18    795 suites  +18   1h 5m 26s ⏱️ - 1m 42s
1 195 tests + 43  1 061 ✅ + 43  134 💤 ±0  0 ❌ ±0 
3 585 runs  +129  3 182 ✅ +129  403 💤 ±0  0 ❌ ±0 

Results for commit ae0835e. ± Comparison against base commit c042b10.

♻️ This comment has been updated with latest results.

jbonofre and others added 3 commits November 16, 2026 16:38
- Introduce org.apache.karaf.services.logging delegating to java.util.logging (JUL)
- Export OSGi LogService R7, SLF4J 2.x/1.7.x, and Commons Logging 1.2
- Provide framework-light and static-framework-light feature definitions
- Update karaf-maven-plugin to support framework-light and static-framework-light
- Configure apache-karaf-light distribution to use framework-light and karaf-logging instead of Pax Logging
- Add the Maven resolver bundle to framework-light, as in framework (apache#2928)
- Keep the file handler at ALL so logger specific levels reach karaf.log
- Keep strong references to the configured JUL loggers, reset the removed ones
- Interpolate placeholders in etc/org.apache.karaf.logging.cfg and apply the
  file settings on configuration update
- Roll karaf.log over by size (10MB, 5 backups by default), keeping the
  active file name
- Register LogReaderService as a ServiceFactory to remove the listeners of a
  bundle when it releases the service
- Isolate the ManagedService as org.osgi.service.cm is an optional import
- Always log AUDIT entries
- Disable console output by default (karaf.log.console), log bundle events
  at DEBUG
- Use Karaf level names in the log format, slf4j.version in the exports,
  remove jansi from the light frameworks
- Document the light logging service
- Copy and truncate karaf.log when it can't be renamed on roll over (on
  Windows, the Karaf Main bootstrap log handlers keep it open), and report
  a failed roll over once instead of retrying it for each record
- Return the most recent log entry first in LogReaderService.getLog()
- Include the Karaf logging service file in dev:dump-create, without
  creating an empty Pax Logging configuration
- Restore the default logging configuration when it's deleted
- Use the Karaf logging configuration in the instances created from an
  Apache Karaf Light root instance
- Name the LogService logger after the calling bundle and keep the level
  given to the LogService in LogEntry.getLevel(), like Pax Logging
- Support nested placeholders in the default values
- Don't export org.osgi.service.log.admin as no LoggerAdmin is registered
- Fall back to org.apache.karaf.services.logging in InstanceServiceImpl.restartInstance and bin/instance(.bat), bin/shell(.bat) when pax-logging-api is absent
- Guard against null processed properties and empty/non-regular file paths in LogDumpProvider
- Handle null logger names in LogServiceImpl.getLogger, avoid per-event LogServiceImpl allocation in Activator, use CopyOnWriteArrayList.addIfAbsent in LogReaderServiceImpl, and remove KarafLogHandler ThreadLocal in finally
- Drop redundant SLF4J dependency versions already managed in karaf-bom
- Extract trailing ServiceReference and Throwable in OsgiLoggerImpl per OSGi R7 Log spec
- Map Logger.ROOT_LOGGER_NAME to JUL root logger in LogServiceImpl
- Skip copying unused etc/org.apache.karaf.log.cfg when creating child instances from a Karaf logging root instance
- InstanceServiceImpl: use String.replace() to build the system/ path,
  replaceAll() with File.separator as replacement fails on Windows
  ("character to be escaped is missing")
- InstanceServiceImpl: look for jline under org.jline (system/org/jline),
  the root instance restart always failed to find it
- InstanceServiceImpl: decide the child instance logging configuration
  from the root startup.properties (which the child uses) instead of the
  presence of etc/org.apache.karaf.logging.cfg
- shell.bat/instance.bat: quote the CLASSPATH assignments in the if
  blocks, a ')' in KARAF_HOME (C:\Program Files (x86)) ended the block
- JulConfig: reset the LogManager like Pax Logging does, so the Karaf
  Main bootstrap log handlers don't write Main records twice to karaf.log
- KarafLogHandler: format the LogEntry message with Formatter.formatMessage
  like karaf.log (MessageFormat only applied with {n} placeholders)
- log.adoc: document the Pax Logging blacklist and cleanup needed when
  using framework-light in a custom distribution
replaceAll() treats its replacement as a regex replacement string, where
the Windows File.separator ("\") is an escape character: completing a
path containing "/" failed with "character to be escaped is missing".
@jbonofre
jbonofre merged commit a4c35fc into apache:main Nov 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant