blob: 9b47ee11ea0787dac6d74131646b449affb437d8 [file] [log] [blame]
Richard S. Hall0b8e3ba2006-10-25 13:26:32 +00001/*
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. 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.LogEntry;
24
25/**
26 * Implementation of the OSGi {@link LogEntry} interface. See section 101
27 * of the OSGi service compendium.
28 * <p>
29 * Provides methods to access the information contained in an individual Log
30 * Service log entry.
31 * <p>
32 * A LogEntry object may be acquired from the
33 * {@link org.osgi.service.log.LogReaderService#getLog()} method or by
34 * registering a {@link org.osgi.service.log.LogListener} object.
35 * @see org.osgi.service.log.LogReaderService#getLog()
36 * @see org.osgi.service.log.LogListener
37 */
38final class LogEntryImpl implements LogEntry {
39
40 /** The bundle that created the LogEntry object. */
41 private final Bundle m_bundle;
42
43 /** The exception associated with this LogEntry object. */
44 private final Throwable m_exception;
45
46 /** The severity level of this LogEntry object. */
47 private final int m_level;
48
49 /** The message associated with this LogEntry object. */
50 private final String m_message;
51
52 /** The service reference associated with this LogEntry object. */
53 private final ServiceReference m_serviceReference;
54
55 /** The system time in milliseconds when this LogEntry object was created. */
56 private final long m_time;
57
58 /**
59 * Create a new instance.
60 * @param bundle the bundle that created the LogEntry object
61 * @param sr the service reference to associate with this LogEntry object
62 * @param level the severity level for this LogEntry object
63 * @param message the message to associate with this LogEntry object
64 * @param exception the exception to associate with this LogEntry object
65 */
66 LogEntryImpl(final Bundle bundle,
67 final ServiceReference sr,
68 final int level,
69 final String message,
70 final Throwable exception) {
71 this.m_bundle = bundle;
72 this.m_exception = LogException.getException(exception);
73 this.m_level = level;
74 this.m_message = message;
75 this.m_serviceReference = sr;
76 this.m_time = System.currentTimeMillis();
77 }
78
79 /**
80 * Returns the bundle that created this LogEntry object.
81 * @return the bundle that created this LogEntry object;<code>null</code> if no
82 * bundle is associated with this LogEntry object
83 */
84 public Bundle getBundle() {
85 return m_bundle;
86 }
87
88 /**
89 * Returns the {@link ServiceReference} object for the service associated with
90 * this LogEntry object.
91 * @return the {@link ServiceReference} object for the service associated with
92 * this LogEntry object; <code>null</code> if no {@link ServiceReference} object
93 * was provided
94 */
95 public ServiceReference getServiceReference() {
96 return m_serviceReference;
97 }
98
99 /**
100 * Returns the severity level of this LogEntry object.
101 * <p>
102 * This is one of the severity levels defined by the
103 * {@link org.osgi.service.logLogService} interface.
104 * @return severity level of this LogEntry object.
105 * @see org.osgi.service.LogService#LOG_ERROR
106 * @see org.osgi.service.LogService#LOG_WARNING
107 * @see org.osgi.service.LogService#LOG_INFO
108 * @see org.osgi.service.LogService#LOG_DEBUG
109 */
110 public int getLevel() {
111 return m_level;
112 }
113
114 /**
115 * Returns the human readable message associated with this LogEntry object.
116 * @return a string containing the message associated with this LogEntry object
117 */
118 public String getMessage() {
119 return m_message;
120 }
121
122 /**
123 * Returns the exception object associated with this LogEntry object.
124 * <p>
125 * The returned exception may not be the original exception. To avoid
126 * references to a bundle defined exception class, thus preventing an
127 * uninstalled bundle from being garbage collected, this LogService will
128 * return an exception object of an implementation defined
129 * {@link Throwable} sub-class.
130 * This exception will maintain as much information as possible from the
131 * original exception object such as the message and stack trace.
132 * @return throwable object of the exception associated with this LogEntry;
133 * <code>null</code> if no exception is associated with this LogEntry object
134 */
135 public Throwable getException() {
136 return m_exception;
137 }
138
139 /**
140 * Returns the value of {@link System#currentTimeMillis()} at the time this
141 * LogEntry object was created.
142 * @return the system time in milliseconds when this LogEntry object was created
143 * @see System#currentTimeMillis()
144 */
145 public long getTime() {
146 return m_time;
147 }
148}