Repository navigation
Add lightweight karaf-logging service and use it in apache-karaf-light - #2949
Merged
Merged
Conversation
- 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
jbonofre
force-pushed
the
karaf-logging
branch
from
November 16, 2026 15:40
48bc314 to
63094a0
Compare
- 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".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a lightweight logging service
org.apache.karaf.services.loggingintended as a simple replacement for Pax Logging in theapache-karaf-lightdistribution.Key Highlights
java.util.logging(JUL), eliminating heavy logging framework dependencies in lightweight environments.org.osgi.service.log1.5) with bundle-specific context andLogReaderService.slf4j-jdk14and backward-compatibleStaticLoggerBinder.jcl-over-slf4j.framework-lightandstatic-framework-lightfeatures to feature definitions.karaf-maven-plugin'sAssemblyMojoto support the light frameworks.apache-karaf-lightto useframework-lightwithorg.apache.karaf.services.logging.pax-loggingbundles so no Pax Logging artifacts are pulled or packaged.etc/org.apache.karaf.logging.cfg.karaf.logis rolled over by size (file.maxSize, default10MB), keepingfile.maxBackupIndexbackups (default5) askaraf.log.1,karaf.log.2, ... Whenkaraf.logcan't be renamed (on Windows, when another process keeps it open), it's copied and truncated. Like Pax Logging, the service resetsjava.util.loggingon startup, which closes the Karaf Main bootstrap log handlers.console = ${karaf.log.console:-OFF}), as in the standard distribution.logger.<name> = <level>) are applied dynamically through Configuration Admin. Deletingetc/org.apache.karaf.logging.cfgrestores the default configuration.LogServicelogger is named after the calling bundle symbolic name.dev:dump-createincludes the Karaf logging service file (it no longer creates an emptyorg.ops4j.pax.loggingconfiguration to look for the Pax Logging files).instance:createusesetc/org.apache.karaf.logging.cfginstead ofetc/org.ops4j.pax.logging.cfgwhen the root instance uses the Karaf logging service.Notes
logfeature requires Pax Logging, thelog:*commands and the JMX LogMBean are not available inapache-karaf-light: log levels are changed inetc/org.apache.karaf.logging.cfg(or withconfig:*commands). This is documented in the user guide (log.adoc).Verification
services/logging,diagnostic/coreandinstancepass cleanly.apache-karaf-lightpackage and runtime boot verified: starts all bundles cleanly, logs properly formatted intodata/log/karaf.log, and shuts down with zero exceptions.dev:dump-createandinstance:createverified on the light distribution.