blob: 054f4f98f79b1cec3f34ca53e28b6739cc0a4231 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Apache Felix Log :: Apache Felix</title>
<link rel="canonical" href="https://felix.apache.org/documentation/subprojects/apache-felix-log.html">
<meta name="generator" content="Antora 2.3.4">
<link rel="stylesheet" href="../../_/css/site.css">
<link rel="icon" href="../../_/img/favicon.png" type="image/x-icon">
</head>
<body class="article">
<header class="header">
<nav class="navbar">
<div class="navbar-brand">
<a class="navbar-item" href="https://felix.apache.org/index.html">
<span>
<img src="../../_/img/logo.png">
</span>
</a>
<button class="navbar-burger" data-target="topbar-nav">
<span></span>
<span></span>
<span></span>
</button>
</div>
<div id="topbar-nav" class="navbar-menu">
<div class="navbar-end">
<a class="navbar-item" href="https://felix.apache.org/index.html">Home</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link" href="#">Subprojects</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="apache-felix-dependency-manager.html">Dependency Manager</a>
<a class="navbar-item" href="apache-felix-event-admin.html">Event Admin</a>
<a class="navbar-item" href="apache-felix-file-install.html">File Install</a>
<a class="navbar-item" href="apache-felix-framework.html">Framework</a>
<a class="navbar-item" href="apache-felix-gogo.html">Gogo Shell</a>
<a class="navbar-item" href="apache-felix-healthchecks.html">Health Checks</a>
<a class="navbar-item" href="apache-felix-inventory.html">Inventory</a>
<a class="navbar-item" href="apache-felix-log.html">Log</a>
<a class="navbar-item" href="apache-felix-logback.html">Logback</a>
<a class="navbar-item" href="apache-felix-maven-bundle-plugin.html">Maven bundle plugin</a>
<a class="navbar-item" href="apache-felix-maven-scr-plugin.html">Maven SCR plugin</a>
<a class="navbar-item" href="apache-felix-metatype-service.html">Metatype Service</a>
<a class="navbar-item" href="apache-felix-preferences-service.html">Preferences Service</a>
<a class="navbar-item" href="apache-felix-remote-shell.html">Remote Shell</a>
<a class="navbar-item" href="apache-felix-script-console-plugin.html">Script console plugin</a>
<a class="navbar-item" href="apache-felix-shell.html">Lightweight shell</a>
<a class="navbar-item" href="apache-felix-shell-tui.html">Shell TUI</a>
<a class="navbar-item" href="apache-felix-web-console.html">Web Console</a>
</div>
</div>
<div class="navbar-item">
<span class="control">
<a class="button is-primary" href="../downloads.html">Downloads</a>
</span>
</div>
</div>
</div>
</nav>
</header>
<div class="body">
<div class="nav-container" data-component="documentation" data-version="master">
<aside class="nav">
<div class="panels">
<div class="nav-panel-menu is-active" data-panel="menu">
<nav class="nav-menu">
<h3 class="title"><a href="../index.html">Documentation</a></h3>
<ul class="nav-list">
<li class="nav-item" data-depth="0">
<ul class="nav-list">
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../documentation.html">Documentation</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../downloads.html">Downloads</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../getting-started.html">Getting Started</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../news.html">News</a>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">Community</span>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../community/project-info.html">Apache Felix Project Info</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../community/contributing.html">Contributing</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../community/projects-using-felix.html">Projects Using Felix</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<span class="nav-text">Development</span>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../development/coding-standards.html">Coding Standards</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../development/dependencies-file-template.html">DEPENDENCIES file template</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../development/provisional-osgi-api-policy.html">Provisional OSGi API Policy</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../development/release-management-nexus.html">Release Management</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../development/site-how-to.html">Site How To</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../development/using-the-osgi-compliance-tests.html">Using the OSGi Compliance Tests</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../faqs.html">FAQS</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../faqs/apache-felix-bundle-plugin-faq.html">Apache Felix Bundle Plugin Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../faqs/apache-felix-scr-plugin-faq.html">Apache Felix SCR Plugin Frequently Asked Questions</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../subprojects.html">Subprojects</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="apache-felix-dependency-manager.html">Apache Felix Dependency Manager</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Guides</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/migrating-from-earlier-versions.html">Apache Felix Dependency Manager - Migrating from earlier versions</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/annotations.html">Dependency Manager - Annotations</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/background.html">Dependency Manager - Background</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/bundles-and-dependencies.html">Dependency Manager - Bundles and Dependencies</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/design-patterns.html">Dependency Manager - Design Patterns</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/development.html">Dependency Manager - Development</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/history.html">Dependency Manager - History</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/javadocs.html">Dependency Manager - JavaDocs</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/migrating-from-other-solutions.html">Dependency Manager - Migrating from other solutions.</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/performance-tuning.html">Dependency Manager - Performance Tuning</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/resources.html">Dependency Manager - Resource adapters</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/whatsnew.html">Dependency Manager - What&#8217;s new in version 4?</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/dm-lambda.html">Dependency Manager Lambda</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/guides/whatsnew-r15.html">What&#8217;s New in R15</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Reference</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/component-adapter.html">Dependency Manager - Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/component-aspect.html">Dependency Manager - Aspect</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/component-bundle-adapter.html">Dependency Manager - Bundle Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/dependency-bundle.html">Dependency Manager - Bundle Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/components.html">Dependency Manager - Components</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/dependency-configuration.html">Dependency Manager - Configuration Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/dependencies.html">Dependency Manager - Dependencies</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/external-links.html">Dependency Manager - External Links</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/component-factory-configuration-adapter.html">Dependency Manager - Factory Configuration Adapter Service</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/component-resource-adapter.html">Dependency Manager - Resource Adapter</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/dependency-resource.html">Dependency Manager - Resource Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/dependency-service.html">Dependency Manager - Service Dependency</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/service-scopes.html">Dependency Manager - Service Scopes</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/component-singleton.html">Dependency Manager - Singleton Component</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/thread-model.html">Dependency Manager - Thread Model</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/reference/dm-annotations.html">Dependency Manager Annotations</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Tutorials</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/tutorials/working-with-annotations.html">Dependency Manager - Annotations</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/tutorials/getting-started.html">Dependency Manager - Getting Started</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/tutorials/leveraging-the-shell.html">Dependency Manager - Leveraging the shell</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-dependency-manager/tutorials/sample-code.html">Dependency Manager sample projects</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-event-admin.html">Apache Felix Event Admin</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-file-install.html">Apache Felix File Install</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="apache-felix-framework.html">Apache Felix Framework</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-framework/apache-felix-framework-bundle-cache.html">Apache Felix Framework Bundle Cache</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-framework/apache-felix-framework-configuration-properties.html">Apache Felix Framework Configuration Properties</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-framework/apache-felix-framework-faq.html">Apache Felix Framework Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-framework/apache-felix-framework-launching-and-embedding.html">Apache Felix Framework Launching and Embedding</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-framework/apache-felix-framework-usage-documentation.html">Apache Felix Framework Usage Documentation</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-framework-security.html">Apache Felix Framework Security</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="apache-felix-gogo.html">Apache Felix Gogo</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-gogo/rfc-147-overview.html">RFC 147 Overview</a>
</li>
</ul>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-healthchecks.html">Apache Felix Health Checks</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-inventory.html">Apache Felix Inventory Printer</a>
</li>
<li class="nav-item is-current-page" data-depth="2">
<a class="nav-link" href="apache-felix-log.html">Apache Felix Log</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-logback.html">Apache Felix Logback</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-maven-bundle-plugin-bnd.html">Apache Felix Maven Bundle Plugin (BND)</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-metatype-service.html">Apache Felix Metatype Service</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-osgi-bundle-repository.html">Apache Felix OSGi Bundle Repository (OBR)</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-preferences-service.html">Apache Felix Preferences Service</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-remote-shell.html">Apache Felix Remote Shell</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-shell.html">Apache Felix Shell</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="apache-felix-shell-tui.html">Apache Felix Shell TUI</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="apache-felix-web-console.html">Apache Felix Web Console</a>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-web-console/extending-the-apache-felix-web-console.html">Extending the Apache Felix Web Console</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-web-console/web-console-restful-api.html">Web Console RESTful API</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="apache-felix-web-console/web-console-security-provider.html">Web Console Security Provider</a>
</li>
<li class="nav-item" data-depth="3">
<button class="nav-item-toggle"></button>
<span class="nav-text">Extensions</span>
<ul class="nav-list">
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-web-console/extending-the-apache-felix-web-console/branding-the-web-console.html">Branding the Web Console</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-web-console/extending-the-apache-felix-web-console/providing-resources.html">Providing Resources</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-web-console/extending-the-apache-felix-web-console/providing-web-console-plugins.html">Providing Web Console Plugins</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-web-console/extending-the-apache-felix-web-console/web-console-logging.html">Web Console Logging</a>
</li>
<li class="nav-item" data-depth="4">
<a class="nav-link" href="apache-felix-web-console/extending-the-apache-felix-web-console/web-console-output-templating.html">Web Console Output Templating</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<button class="nav-item-toggle"></button>
<a class="nav-link" href="../tutorials-examples-and-presentations.html">Tutorials</a>
<ul class="nav-list">
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-application-demonstration.html">Apache Felix Application Demonstration</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial.html">Apache Felix OSGi Tutorial</a>
</li>
<li class="nav-item" data-depth="2">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-faq.html">OSGi Frequently Asked Questions</a>
</li>
<li class="nav-item" data-depth="2">
<button class="nav-item-toggle"></button>
<span class="nav-text">OSGI Tutorial</span>
<ul class="nav-list">
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-1.html">Apache Felix Tutorial Example 1 - Service Event Listener Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-2.html">Apache Felix Tutorial Example 2</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-2b.html">Apache Felix Tutorial Example 2b</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-3.html">Apache Felix Tutorial Example 3</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-4.html">Apache Felix Tutorial Example 4</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-5.html">Apache Felix Tutorial Example 5</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-6.html">Example 6 - Spell Checker Service Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-7.html">Example 7 - Spell Checker Client Bundle</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-8.html">Example 8 - Spell Checker Service using Service Binder</a>
</li>
<li class="nav-item" data-depth="3">
<a class="nav-link" href="../tutorials-examples-and-presentations/apache-felix-osgi-tutorial/apache-felix-tutorial-example-9.html">Example 9 - Spell Checker Service using Declarative Services</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../license.html">Apache License 2.0</a>
</li>
<li class="nav-item" data-depth="1">
<a class="nav-link" href="../site-map.html">Site map</a>
</li>
</ul>
</li>
</ul>
</nav>
</div>
<div class="nav-panel-explore" data-panel="explore">
<div class="context">
<span class="title">Documentation</span>
<span class="version">master</span>
</div>
<ul class="components">
<li class="component is-current">
<span class="title">Documentation</span>
<ul class="versions">
<li class="version is-current is-latest">
<a href="../index.html">master</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</aside>
</div>
<main class="article">
<div class="toolbar" role="navigation">
<button class="nav-toggle"></button>
<a href="../index.html" class="home-link"></a>
<nav class="breadcrumbs" aria-label="breadcrumbs">
<ul>
<li><a href="../index.html">Documentation</a></li>
<li><a href="../subprojects.html">Subprojects</a></li>
<li><a href="apache-felix-log.html">Apache Felix Log</a></li>
</ul>
</nav>
<div class="edit-this-page"><a href="https://github.com/apache/felix-antora-site/edit/main/modules/ROOT/pages/subprojects/apache-felix-log.adoc">Edit this Page</a></div>
</div>
<div class="content">
<article class="doc">
<h1 class="page">Apache Felix Log</h1>
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>The <a href="https://osgi.org/specification/osgi.cmpn/7.0.0/">OSGi Service Compendium specification</a> defines a general purpose <a href="https://osgi.org/specification/osgi.cmpn/7.0.0/service.log.html">Log Service</a> for the OSGi Platform.
It is a very simple specification that doesn&#8217;t provide all the functionality commonly available in enterprise-level logging tools, but its extensible service model can be used to build fairly sophisticated logging solutions.</p>
</div>
<div class="paragraph">
<p>The Log Service specification defines the following entities:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><em>`org.osgi.service.log.Logger`</em> - (<em>since 1.4</em>) interface that allows a bundle to log information, including a message, a level, an exception, and a <code>ServiceReference</code> object.
The formatting style using <code>{}</code> placeholders follows the <em>slf4j</em> approach.
A derivative of <code>Logger</code> called <code>FormatterLogger</code> uses the <code>java.util.Formatter</code> syntax.</p>
</li>
<li>
<p><em>`org.osgi.service.log.LoggerFactory`</em> - (<em>since 1.4</em>) service interface that allows a bundle to obtain a Logger.
A Logger is named and associated with a <code>Bundle</code> object.</p>
</li>
<li>
<p><em>`org.osgi.service.log.admin.LoggerContext`</em> - (<em>since 1.4</em>) interface that allows the configuration of effective logging levels for a Bundle.
The configuration can be set in Configuration Admin and via method calls.</p>
</li>
<li>
<p><em>`org.osgi.service.log.admin.LoggerAdmin`</em> - (<em>since 1.4</em>) interface for managing the configuration of log levels.</p>
</li>
<li>
<p><em>`org.osgi.service.log.LogService`</em> - <em>legacy</em> service interface that allows a bundle to log information, including a message, a level, an exception, a <code>ServiceReference</code> object, and a <code>Bundle</code> object.
The methods of this service are deprecated and it is recommended to use LoggerFactory and Loggers instead.</p>
</li>
<li>
<p><em>`org.osgi.service.log.LogReaderService`</em> - service interface that allows access to a list of recent <code>LogEntry</code> objects, and allows the registration of a <code>LogListener</code> object that receives <code>LogEntry</code> objects as they are created.</p>
</li>
<li>
<p><em>`org.osgi.service.log.LogEntry`</em> - interface defining a log entry.</p>
</li>
<li>
<p><em>`org.osgi.service.log.LogListener`</em> - interface defining a listener for log entries, which is notified about new log entries.</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_accessing_loggers"><a class="anchor" href="#_accessing_loggers"></a>Accessing Loggers</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Loggers are obtained through the <code>LoggerFactory</code> service:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public class Activator implements BundleActivator
{
private volatile LoggerFactory loggerFactory;
public void start(BundleContext context) throws Exception
{
ServiceReference ref = context.getServiceReference(LoggerFactory.class.getName());
if (ref != null)
{
loggerFactory = (LoggerFactory) context.getService(ref);
}
}
//..</code></pre>
</div>
</div>
<div class="paragraph">
<p>Elsewhere in the bundle you can then use the <code>LoggerFactory</code> to get a <code>Logger</code> for any class:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> Logger logger = loggerFactory.getLogger(Foo.class);</code></pre>
</div>
</div>
<div class="paragraph">
<p>Declarative Services (<em>since 1.4</em>) has a convenient integration which allows a component to obtain a logger specific to it&#8217;s class with little effort by using a reference who&#8217;s service type is <code>LoggerFactory</code> while the injection type is either <code>Logger</code> or <code>FormatterLogger</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> @Reference(service = LoggerFactory.class)
private Logger logger;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>Logger</code> interface defines 6 levels of logging to coincide with most other log APIs:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>AUDIT</p>
</li>
<li>
<p>ERROR</p>
</li>
<li>
<p>WARN</p>
</li>
<li>
<p>INFO</p>
</li>
<li>
<p>DEBUG</p>
</li>
<li>
<p>TRACE</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>Each level has methods on the Logger interface appropriate to that level such as <code>.info(...)</code> and <code>.isInfoEnabled()</code>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_configuring_log_levels"><a class="anchor" href="#_configuring_log_levels"></a>Configuring Log Levels</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Since 1.4 the <strong>Log Service Specification</strong> provides the ability to manage the log levels both programatically and through <strong>Configuration Admin</strong>.</p>
</div>
<div class="paragraph">
<p>Programatic configuration is achieved through the <code>LoggerAdmin</code> service:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">ServiceReference ref = context.getServiceReference(
LoggerAdmin.class.getName());
if (ref != null)
{
LoggerAdmin loggerAdmin = (LoggerAdmin) context.getService(ref);
// get the ROOT logger context
LoggerContext rootContext = loggerAdmin.getLoggerContext(null);
Map&lt;String, LogLevel&gt; levels = rootContext.getLogLevels();
// adjust the levels
rootContext.setLogLevels(levels);
// get the levels for a bundle (felix scr in this case)
LoggerContext scrContext = loggerAdmin.getLoggerContext(
"org.apache.felix.scr");
// set all of scr to DEBUG mode
scrContext.setLogLevels(
Collections.singletonMap(
Logger.ROOT_LOGGER_NAME, LogLevel.DEBUG));
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Likewise logging configuration can be handled through <strong>Configuration Admin</strong>.
Following the previous example of configuring <strong>Felix SCR</strong> for <code>DEBUG</code> mode:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>create a configuration object whose PID is <em>`org.osgi.service.log.admin|org.apache.felix.scr`</em></p>
</li>
<li>
<p>set the property <code>ROOT</code> in the configuration to <code>DEBUG</code> e.g.
<code>ROOT=DEBUG</code></p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_accessing_the_log_service_legacy"><a class="anchor" href="#_accessing_the_log_service_legacy"></a>Accessing the log service (legacy)</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To access a <code>LogService</code> instance it is necessary to look it up in the OSGi service registry as demonstrated in the following code snippet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public class Activator implements BundleActivator
{
public void start(BundleContext context) throws Exception
{
ServiceReference ref = context.getServiceReference(LogService.class.getName());
if (ref != null)
{
LogService log = (LogService) context.getService(ref);
// Use the log...
}
}
//..</code></pre>
</div>
</div>
<div class="paragraph">
<p>It is possible, and advisable, to use more sophisticated service acquisition mechanisms like a Service Tracker, Declarative Services or iPOJO.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_using_the_log_service_legacy"><a class="anchor" href="#_using_the_log_service_legacy"></a>Using the log service (legacy)</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The <code>LogService</code> interface provides four methods for logging:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java">public interface LogService
{
//..
// Log a message specifying a log level
public log(int level, java.lang.String message)
// Log an exception
public log(int level, java.lang.String message, java.lang.Throwable exception)
// Log a message specifying the ServiceReference that generated it
public log(ServiceReference sr, int level, java.lang.String message)
// Log a message specifying the ServiceReference and exception
public log(ServiceReference sr, int level, java.lang.String message, java.lang.Throwable exception)
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Log levels are defined in the same interface:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>LogService.LOG_DEBUG</code></p>
</li>
<li>
<p><code>LogService.LOG_INFO</code></p>
</li>
<li>
<p><code>LogService.LOG_WARNING</code></p>
</li>
<li>
<p><code>LogService.LOG_ERROR</code></p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_retrieving_log_entries"><a class="anchor" href="#_retrieving_log_entries"></a>Retrieving log entries</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The <code>LogReaderService</code> provides a <code>getLog()</code> method to retrieve an <code>Enumeration</code> of the latest log entries.
The following code snippets demonstrates how to retrieve it from the service registry and use it:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> ServiceReference ref = context.getServiceReference(LogReaderService.class.getName());
if (ref != null)
{
LogReaderService reader = (LogReaderService) context.getService(ref);
Enumeration&lt;LogEntry&gt; latestLogs = reader.getLog();
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_creating_and_registering_a_loglistener"><a class="anchor" href="#_creating_and_registering_a_loglistener"></a>Creating and registering a <code>LogListener</code></h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Log Service specification doesn&#8217;t define any particular entity to store, display, or write log entries;
it&#8217;s up to the developer to implement this functionality or to choose an available implementation capable of doing that.
To create such a bundle, the first step is to create an implementation of the <code>LogListener</code> interface.
The following code shows a simple implementation that echoes the log message:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> public class LogWriter implements LogListener
{
// Invoked by the log service implementation for each log entry
public void logged(LogEntry entry)
{
System.out.println(entry.getMessage());
}
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The only method to implement is <code>logged()</code> method, which is called every time a log entry is created in the associated logging service.
A <code>LogListener</code> implementation must be registered with the <code>LogReaderService</code> so it can start receiving log entries, as demonstrated in the following code snippet:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-java hljs" data-lang="java"> ServiceReference ref = context.getServiceReference(LogReaderService.class.getName());
if (ref != null)
{
LogReaderService reader = (LogReaderService) context.getService(ref);
reader.addLogListener(new LogWriter());
}</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_setup_of_apache_felix_log_service"><a class="anchor" href="#_setup_of_apache_felix_log_service"></a>Setup of Apache Felix Log Service</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The Apache Felix Log Service bundle doesn&#8217;t have any specific dependency on Felix, so it can run on any OSGi container.
For its configuration, it will use the following optional system properties:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Property</th>
<th class="tableblock halign-left valign-top">Default</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.apache.felix.log.maxSize</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">100</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The maximum size of the log history.
A value of -1 means the log has no maximum size;
a value of 0 means that no historical information is maintained</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.apache.felix.log.storeDebug</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Determines whether or not debug messages will be stored in the history</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>org.osgi.service.log.admin.loglevel</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>WARN</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The default log level of the root Logger Context</p></td>
</tr>
</tbody>
</table>
</div>
</div>
</article>
<aside class="toc sidebar" data-title="Contents" data-levels="2">
<div class="toc-menu"></div>
</aside>
</div>
</main>
</div>
<footer class="footer">
<p>Content licensed under AL2. UI licensed under MPL-2.0 with extensions licensed under AL2</p>
</footer>
<script src="../../_/js/site.js"></script>
<script async src="../../_/js/vendor/highlight.js"></script>
</body>
</html>