blob: b0230155092adc79e7c62f82ddea0e708796bb77 [file] [log] [blame]
Richard S. Hallddf2e142009-09-30 17:03:45 +00001/*
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +00002 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Richard S. Hall44002cf2009-02-11 21:47:26 +000019package org.apache.felix.log;
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000020
21import org.osgi.framework.Bundle;
22import org.osgi.framework.ServiceReference;
23import org.osgi.service.log.LogService;
24
25/**
26 * Implementation of the OSGi {@link LogService}.
27 */
Richard S. Hallddf2e142009-09-30 17:03:45 +000028final class LogServiceImpl implements LogService
29{
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000030 /** The log implementation. */
31 private final Log m_log;
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000032 /** The bundle associated with this implementation. */
33 private final Bundle m_bundle;
34
35 /**
36 * Create a new instance.
37 * @param log the log implementation
38 * @param bundle the bundle associated with this implementation
39 */
Richard S. Hallddf2e142009-09-30 17:03:45 +000040 LogServiceImpl(final Log log, final Bundle bundle)
41 {
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000042 this.m_log = log;
43 this.m_bundle = bundle;
44 }
45
46 /**
47 * Log the specified message at the specified level.
48 * @param level the level to log the message at
49 * @param message the message to log
50 */
Richard S. Hallddf2e142009-09-30 17:03:45 +000051 public void log(final int level, final String message)
52 {
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000053 log(null, level, message, null);
54 }
55
56 /**
57 * Log the specified message along with the specified exception at the
58 * specified level.
59 * @param level the level to log the message and exception at
60 * @param message the message to log
61 * @param exception the exception to log
62 */
63 public void log(final int level,
Richard S. Hallddf2e142009-09-30 17:03:45 +000064 final String message,
65 final Throwable exception)
66 {
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000067 log(null, level, message, exception);
68 }
69
70 /**
71 * Log the specified message along with the speicified service reference
72 * at the specified level.
73 * @param sr the service reference of the service that produced the message
74 * @param level the level to log the message at
75 * @param message the message to log
76 */
77 public void log(final ServiceReference sr,
Richard S. Hallddf2e142009-09-30 17:03:45 +000078 final int level,
79 final String message)
80 {
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000081 log(sr, level, message, null);
82 }
83
84 /**
85 * Log the specified message along with the specified exception and
86 * service reference at the specified level.
87 * @param sr the service reference of the service that produced the message
88 * @param level the level to log the message at
89 * @param message the message to log
90 * @param exception the exception to log
91 */
92 public void log(final ServiceReference sr,
Richard S. Hallddf2e142009-09-30 17:03:45 +000093 final int level,
94 final String message,
95 final Throwable exception)
96 {
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +000097 m_log.addEntry(new LogEntryImpl((sr != null) ? sr.getBundle() : m_bundle,
Richard S. Hallddf2e142009-09-30 17:03:45 +000098 sr,
99 level,
100 message,
101 exception));
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +0000102 }
Richard S. Hallddf2e142009-09-30 17:03:45 +0000103}