Skip to content

Commit

Permalink
felix.log: Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilx committed Dec 13, 2024
1 parent 4f21344 commit 87f75f4
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion log/src/main/java/org/apache/felix/log/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static boolean getStoreDebug(final BundleContext context)
String storeDebugPropValue = context.getProperty(STORE_DEBUG_PROPERTY);
if (storeDebugPropValue != null)
{
storeDebug = Boolean.valueOf(storeDebugPropValue).booleanValue();
storeDebug = Boolean.parseBoolean(storeDebugPropValue);
}

return storeDebug;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ConfigurationListenerImpl {
final Log m_log;
final LoggerAdminImpl m_loggerAdmin;

public ConfigurationListenerImpl(final BundleContext context, final Log log, final LoggerAdminImpl loggerAdmin) throws Exception {
ConfigurationListenerImpl(final BundleContext context, final Log log, final LoggerAdminImpl loggerAdmin) throws Exception {
m_context = context;
m_log = log;
m_loggerAdmin = loggerAdmin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@

public class FormatterLoggerImpl extends LoggerImpl implements FormatterLogger {

public FormatterLoggerImpl(
FormatterLoggerImpl(
final String name, final Bundle bundle, final Log log, final LoggerAdminImpl loggerAdmin) {

super(name, bundle, log, loggerAdmin);
}

@Override
String format(String format, LogParameters logParameters) {
StringBuilder sb = new StringBuilder();

Expand Down
2 changes: 1 addition & 1 deletion log/src/main/java/org/apache/felix/log/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ synchronized Enumeration<LogEntry> getEntries()
"FrameworkEvent STARTED",
"FrameworkEvent ERROR",
"FrameworkEvent PACKAGES REFRESHED",
"FrameworkEvent STARTLEVEL CHANGED",
"FrameworkEvent STARTLEVEL CHANGED",
"FrameworkEvent WARNING",
"FrameworkEvent INFO"
};
Expand Down
6 changes: 6 additions & 0 deletions log/src/main/java/org/apache/felix/log/LogEntryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ final class LogEntryImpl implements LogEntry
* @return the bundle that created this LogEntry object;<code>null</code> if no
* bundle is associated with this LogEntry object
*/
@Override
public Bundle getBundle()
{
return m_bundle;
Expand All @@ -155,6 +156,7 @@ public Bundle getBundle()
* this LogEntry object; <code>null</code> if no {@link ServiceReference} object
* was provided
*/
@Override
public ServiceReference<?> getServiceReference()
{
return m_serviceReference;
Expand All @@ -171,6 +173,7 @@ public ServiceReference<?> getServiceReference()
* @see org.osgi.service.LogService#LOG_INFO
* @see org.osgi.service.LogService#LOG_DEBUG
*/
@Override
public int getLevel()
{
if (m_legacyLevel != m_level.ordinal()) {
Expand All @@ -184,6 +187,7 @@ public int getLevel()
* Returns the human readable message associated with this LogEntry object.
* @return a string containing the message associated with this LogEntry object
*/
@Override
public String getMessage()
{
return m_message;
Expand All @@ -202,6 +206,7 @@ public String getMessage()
* @return throwable object of the exception associated with this LogEntry;
* <code>null</code> if no exception is associated with this LogEntry object
*/
@Override
public Throwable getException()
{
return m_exception;
Expand All @@ -213,6 +218,7 @@ public Throwable getException()
* @return the system time in milliseconds when this LogEntry object was created
* @see System#currentTimeMillis()
*/
@Override
public long getTime()
{
return m_time;
Expand Down
5 changes: 3 additions & 2 deletions log/src/main/java/org/apache/felix/log/LogListenerThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void shutdown()
* The main method of the thread: waits for new messages to be receieved
* and then delivers them to any registered log listeners.
*/
@Override
public void run()
{
while (!isInterrupted())
Expand Down Expand Up @@ -138,10 +139,10 @@ public void run()
{
// Take a snapshot of all current listeners and deliver all
// pending messages to them...
List<LogListener> listeners = new ArrayList<>();
List<LogListener> listeners;
synchronized (m_listeners)
{
listeners.addAll(m_listeners);
listeners = new ArrayList<>(m_listeners);
}

Iterator<LogEntry> entriesIt = entriesToDeliver.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ final class LogNodeEnumeration implements Enumeration<LogEntry>
* Determines whether there are any more elements to return.
* @return <code>true</code> if there are more elements; <code>false</code> otherwise
*/
@Override
public boolean hasMoreElements()
{
return m_next != null;
Expand All @@ -57,6 +58,7 @@ public boolean hasMoreElements()
* Returns the current element and moves onto the next element.
* @return the current element
*/
@Override
public LogEntry nextElement()
{
LogEntry result = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ final class LogReaderServiceFactory implements ServiceFactory<LogReaderService>
* @param registration the service registration
* @return the log reader service implementation for the specified bundle
*/
@Override
public LogReaderService getService(final Bundle bundle,
final ServiceRegistration<LogReaderService> registration)
{
Expand All @@ -60,6 +61,7 @@ public LogReaderService getService(final Bundle bundle,
* @param registration the service registration
* @param service the service to release
*/
@Override
public void ungetService(final Bundle bundle,
final ServiceRegistration<LogReaderService> registration,
final LogReaderService service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class LogServiceFactory implements ServiceFactory<LogService>

/**
* Create a new instance.
* @param log the log to associate the service implementations with.,
* @param loggerAdminImpl
*/
LogServiceFactory(final LoggerAdminImpl loggerAdminImpl)
{
Expand Down
3 changes: 1 addition & 2 deletions log/src/main/java/org/apache/felix/log/LogServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ final class LogServiceImpl implements LogService

/**
* Create a new instance.
* @param log the log implementation
* @param bundle the bundle associated with this implementation
* @param serviceReference
* @param loggerAdminImpl
*/
LogServiceImpl(final Bundle bundle, final LoggerAdminImpl loggerAdminImpl)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class LoggerAdminImpl implements LoggerAdmin {
private final ConcurrentMap<String, LoggerContext> m_contexts = new ConcurrentHashMap<>();
private final ConcurrentMap<LoggerKey, Logger> _loggers = new ConcurrentHashMap<>();

public LoggerAdminImpl(final String defaultLogLevelString, final Log log) {
LoggerAdminImpl(final String defaultLogLevelString, final Log log) {
m_rootContext = new RootLoggerContextImpl(defaultLogLevelString, this);
m_log = log;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ public LoggerContextImpl(String name, LoggerAdminImpl loggerAdminImpl, LoggerCon
_rootContext = rootLoggerContext;
}

@Override
public String getName() {
return _name;
}

@Override
public LogLevel getEffectiveLogLevel(String name) {
_lock.lock();
try {
if (_levels != null && !_levels.isEmpty()) {
String copy = name;
LogLevel level;
while (copy.length() > 0) {
while (!copy.isEmpty()) {
level = _levels.get(copy);
if (level != null) {
return level;
Expand All @@ -74,6 +76,7 @@ public LogLevel getEffectiveLogLevel(String name) {
}
}

@Override
public Map<String, LogLevel> getLogLevels() {
_lock.lock();
try {
Expand All @@ -87,6 +90,7 @@ public Map<String, LogLevel> getLogLevels() {
}
}

@Override
public void setLogLevels(Map<String, LogLevel> logLevels) {
_lock.lock();
try {
Expand All @@ -98,6 +102,7 @@ public void setLogLevels(Map<String, LogLevel> logLevels) {
}
}

@Override
public void clear() {
_lock.lock();
try {
Expand All @@ -108,6 +113,7 @@ public void clear() {
}
}

@Override
public boolean isEmpty() {
_lock.lock();
try {
Expand Down
4 changes: 2 additions & 2 deletions log/src/main/java/org/apache/felix/log/LoggerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public class LoggerImpl implements Logger {

protected final String m_name;
protected final Bundle m_bundle;
protected final Log m_log;
final Log m_log;
protected final LoggerAdminImpl m_loggerAdmin;

public LoggerImpl(final String name, final Bundle bundle, final Log log, final LoggerAdminImpl loggerAdmin) {
LoggerImpl(final String name, final Bundle bundle, final Log log, final LoggerAdminImpl loggerAdmin) {
m_name = name;
m_bundle = bundle;
m_log = log;
Expand Down
16 changes: 2 additions & 14 deletions log/src/main/java/org/apache/felix/log/RootLoggerContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package org.apache.felix.log;

import java.util.Dictionary;
import java.util.Map;

import org.osgi.service.log.LogLevel;
import org.osgi.service.log.Logger;

Expand All @@ -45,12 +42,13 @@ public RootLoggerContextImpl(String defaultLogLevelString, LoggerAdminImpl logge
_defaultLevel = defaultLogLevel;
}

@Override
public LogLevel getEffectiveLogLevel(String name) {
_lock.lock();
try {
if (_levels != null && !_levels.isEmpty()) {
LogLevel level;
while (name.length() > 0) {
while (!name.isEmpty()) {
level = _levels.get(name);
if (level != null) {
return level;
Expand All @@ -67,16 +65,6 @@ public LogLevel getEffectiveLogLevel(String name) {
}
}

@Override
public void setLogLevels(Map<String, LogLevel> logLevels) {
super.setLogLevels(logLevels);
}

@Override
void updateLoggerContext(Dictionary<String, Object> properties) {
super.updateLoggerContext(properties);
}

private LogLevel getEffectiveRootLogLevel() {
if (_levels == null) return _defaultLevel;
LogLevel logLevel = _levels.get(Logger.ROOT_LOGGER_NAME);
Expand Down

0 comments on commit 87f75f4

Please sign in to comment.