Skip to content

Commit

Permalink
📜 ... temporary refactoring/removal of log message consistency mechan…
Browse files Browse the repository at this point in the history
…ism to avoid linter error 🤔

Signed-off-by: Patrik Gfeller <[email protected]>
  • Loading branch information
pgfeller committed Mar 16, 2024
1 parent 647ce2b commit 566ee5d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.openhab.binding.huesync.internal.api.dto.registration.HueSyncRegistration;
import org.openhab.binding.huesync.internal.api.dto.registration.HueSyncRegistrationRequest;
import org.openhab.binding.huesync.internal.config.HueSyncConfiguration;
import org.openhab.binding.huesync.internal.log.HueSyncLogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
Expand All @@ -55,7 +55,7 @@ public class HueSyncConnection {
private static final String REGISTRATIONS = "registrations";

private static final ObjectMapper ObjectMapper = new ObjectMapper();
private final Logger logger = LoggerFactory.getLogger(HueSyncConnection.class);
private final Logger logger = HueSyncLogFactory.getLogger(HueSyncConnection.class);

private @NonNull HttpClient httpClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.huesync.internal.HueSyncConstants;
import org.openhab.binding.huesync.internal.log.HueSyncLogFactory;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.config.discovery.DiscoveryService;
Expand All @@ -37,7 +38,6 @@
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link HueSyncDiscoveryParticipant} is responsible for discovering
Expand All @@ -49,7 +49,7 @@
@Component(service = MDNSDiscoveryParticipant.class, configurationPid = "mdnsdiscovery.huesync")
public class HueSyncDiscoveryParticipant implements MDNSDiscoveryParticipant {
@SuppressWarnings("null")
private Logger logger = LoggerFactory.getLogger(HueSyncDiscoveryParticipant.class);
private Logger logger = HueSyncLogFactory.getLogger(HueSyncDiscoveryParticipant.class);

/**
*
Expand Down Expand Up @@ -101,7 +101,9 @@ public String getServiceType() {
.withProperties(properties).build();
return result;
} catch (Exception e) {
logger.error("Unable to query device information for {}: {}", service.getQualifiedName(), e);
// TODO ...
// logger.error("Unable to query device information for {}: {}",
// service.getQualifiedName(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.openhab.binding.huesync.internal.connection.HueSyncConnection;
import org.openhab.binding.huesync.internal.connection.HueSyncTrustManagerProvider;
import org.openhab.binding.huesync.internal.exceptions.HueSyncApiException;
import org.openhab.binding.huesync.internal.util.HueSyncLogLocalizer;
import org.openhab.binding.huesync.internal.log.HueSyncLogFactory;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.io.net.http.HttpClientFactory;
import org.openhab.core.io.net.http.TlsTrustManagerProvider;
Expand All @@ -42,7 +42,6 @@
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link HueSyncHandler} is responsible for handling commands, which are
Expand All @@ -62,7 +61,7 @@ public class HueSyncHandler extends BaseThingHandler {
static final String PROPERTY_NETWORK_STATE = "networkState";

@SuppressWarnings("null")
private final Logger logger = LoggerFactory.getLogger(HueSyncHandler.class);
private final Logger logger = HueSyncLogFactory.getLogger(HueSyncHandler.class);

private HueSyncConfiguration config;

Expand Down Expand Up @@ -136,8 +135,11 @@ public void initialize() {
}

private void logInitializationException(Exception e) {
this.logger.error(HueSyncLogLocalizer.getResourceString("@text/logger.initialization-problem"),
this.thing.getLabel(), this.thing.getUID(), HueSyncLogLocalizer.getResourceString(e.getMessage()));
// TODO: Use EN local string to format log & exception message ...

// this.logger.error("@text/logger.initialization-problem",
// this.thing.getLabel(), this.thing.getUID(),
// HueSyncLocalizer.getResourceString(e.getMessage()));
}

@SuppressWarnings("null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.huesync.internal.util;
package org.openhab.binding.huesync.internal.i18n;

import java.util.Locale;

Expand All @@ -21,17 +21,20 @@
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;

public class HueSyncLogLocalizer {
/**
*
* @author Patrik Gfeller - Initial Contribution
*/
public class HueSyncLocalizer {

private static final Locale locale = Locale.ENGLISH;

private static final BundleContext bundleContext = FrameworkUtil.getBundle(HueSyncLogLocalizer.class)
private static final BundleContext bundleContext = FrameworkUtil.getBundle(HueSyncLocalizer.class)
.getBundleContext();
private static final @Nullable ServiceReference<@NonNull TranslationProvider> serviceReference = bundleContext != null
? bundleContext.getServiceReference(TranslationProvider.class)
: null;

// TODO: Resolve warning ...
private static final TranslationProvider translationProvider = serviceReference != null
? bundleContext.getService(serviceReference)
: null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.huesync.internal.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Helper class to use [en] resource files to log messages to be consistent
* with exception message displayed on screen.
*
* @author Patrik Gfeller - Initial contribution
*/
public class HueSyncLogFactory {

public static Logger getLogger(Class<?> clazz) {
return LoggerFactory.getLogger(clazz);
}
}

0 comments on commit 566ee5d

Please sign in to comment.