Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 1 | /* |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 2 | * 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. Hall | 44002cf | 2009-02-11 21:47:26 +0000 | [diff] [blame] | 19 | package org.apache.felix.log; |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 20 | |
| 21 | import org.osgi.framework.Bundle; |
| 22 | import org.osgi.framework.ServiceReference; |
| 23 | import org.osgi.service.log.LogService; |
| 24 | |
| 25 | /** |
| 26 | * Implementation of the OSGi {@link LogService}. |
| 27 | */ |
Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 28 | final class LogServiceImpl implements LogService |
| 29 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 30 | /** The log implementation. */ |
| 31 | private final Log m_log; |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 32 | /** 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. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 40 | LogServiceImpl(final Log log, final Bundle bundle) |
| 41 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 42 | 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. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 51 | public void log(final int level, final String message) |
| 52 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 53 | 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. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 64 | final String message, |
| 65 | final Throwable exception) |
| 66 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 67 | 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. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 78 | final int level, |
| 79 | final String message) |
| 80 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 81 | 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. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 93 | final int level, |
| 94 | final String message, |
| 95 | final Throwable exception) |
| 96 | { |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 97 | m_log.addEntry(new LogEntryImpl((sr != null) ? sr.getBundle() : m_bundle, |
Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 98 | sr, |
| 99 | level, |
| 100 | message, |
| 101 | exception)); |
Richard S. Hall | 0b8e3ba | 2006-10-25 13:26:32 +0000 | [diff] [blame] | 102 | } |
Richard S. Hall | ddf2e14 | 2009-09-30 17:03:45 +0000 | [diff] [blame] | 103 | } |