Martin Peřina has uploaded a new change for review. Change subject: core: Replace oVirt logger with slf4j in utils ......................................................................
core: Replace oVirt logger with slf4j in utils Replaces oVirt logger with slf4j in utils module. Change-Id: I0b99ca3947a3ad778601da27decdbad751cfa19c Bug-Url: https://bugzilla.redhat.com/1109871 Signed-off-by: Martin Perina <mper...@redhat.com> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ConfigUtilsBase.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ErrorTranslatorImpl.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/MacAddressRangeUtils.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ResourceUtils.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ThreadUtils.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/TarInMemoryExport.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ejb/EJBUtilsStrategy.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoader.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfLogEventHandler.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfParser.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/FenceConfigHelper.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/VdsFenceOptions.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/RandomUtilsSeedingRule.java M backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/customprop/DevicePropertiesUtilsTest.java 21 files changed, 152 insertions(+), 142 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/64/34264/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ConfigUtilsBase.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ConfigUtilsBase.java index 0e6c7c7..c8e0701 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ConfigUtilsBase.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ConfigUtilsBase.java @@ -15,14 +15,15 @@ import org.ovirt.engine.core.common.config.TypeConverterAttribute; import org.ovirt.engine.core.compat.TimeSpan; import org.ovirt.engine.core.compat.Version; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.utils.serialization.json.JsonObjectDeserializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Config Utils Base Class */ public abstract class ConfigUtilsBase implements IConfigUtilsInterface { + private static final Logger log = LoggerFactory.getLogger(ConfigUtilsBase.class); @Override public final boolean getBoolValue(String name, String defaultValue) { @@ -127,7 +128,7 @@ // Ignore temporary values inserted to vdc_options by upgrades as // flags. if (!name.startsWith(TEMP)) { - log.warnFormat("Could not find enum value for option: {0}", name); + log.warn("Could not find enum value for option: '{}'", name); } return null; } else { @@ -153,8 +154,6 @@ } } } - - private static final Log log = LogFactory.getLog(ConfigUtilsBase.class); @SuppressWarnings("unchecked") @Override diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ErrorTranslatorImpl.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ErrorTranslatorImpl.java index b8e7a96..bbbfe5a 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ErrorTranslatorImpl.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ErrorTranslatorImpl.java @@ -10,13 +10,13 @@ import org.apache.commons.lang.text.StrSubstitutor; import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.common.interfaces.ErrorTranslator; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public final class ErrorTranslatorImpl implements ErrorTranslator { private static final long ONE_HOUR = 60 * 60 * 1000L; - private static final Log log = LogFactory.getLog(ErrorTranslatorImpl.class); + private static final Logger log = LoggerFactory.getLogger(ErrorTranslatorImpl.class); private List<String> messageSources; private Locale standardLocale; private Map<String, String> standardMessages; @@ -24,12 +24,12 @@ // Will assume these are property files, not ResxFiles. public ErrorTranslatorImpl(String... errorFileNames) { - log.infoFormat("Start initializing " + getClass().getSimpleName()); + log.info("Start initializing {}", getClass().getSimpleName()); messageSources = asList(errorFileNames); standardLocale = Locale.getDefault(); standardMessages = retrieveByLocale(standardLocale); messagesByLocale = new ReapedMap<Locale, Map<String, String>>(ONE_HOUR, true); - log.infoFormat("Finished initializing " + getClass().getSimpleName()); + log.info("Finished initializing {}", getClass().getSimpleName()); } private synchronized Map<String, String> getMessages(Locale locale) { @@ -61,11 +61,12 @@ if (!messages.containsKey(key)) { messages.put(key, bundle.getString(key)); } else { - log.warnFormat("Code {0} appears more than once in string table.", key); + log.warn("Code '{}' appears more than once in string table.", key); } } } catch (RuntimeException e) { - log.errorFormat("File: {0} could not be loaded: {1}", messageSource, e.toString()); + log.error("File: '{}' could not be loaded: {}", messageSource, e.toString()); + log.debug("Exception", e); } return messages; } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/MacAddressRangeUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/MacAddressRangeUtils.java index 81cb919..3990a1d 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/MacAddressRangeUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/MacAddressRangeUtils.java @@ -8,12 +8,12 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.LongRange; import org.apache.commons.lang.math.Range; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MacAddressRangeUtils { - private static final Log log = LogFactory.getLog(MacAddressRangeUtils.class); + private static final Logger log = LoggerFactory.getLogger(MacAddressRangeUtils.class); private static final int HEX_RADIX = 16; @@ -87,14 +87,14 @@ } if (rangeStart > rangeEnd) { - log.warnFormat( - "User supplied range({0}) contains only multicast addresses, so this range is not usable.", range); + log.warn( + "User supplied range({}) contains only multicast addresses, so this range is not usable.", range); return null; } final LongRange result = new LongRange(rangeStart, rangeEnd); if (trimmingOccurred) { - log.warnFormat("User supplied range({0}) need to be trimmed to {1}, ", range, result); + log.warn("User supplied range({}) need to be trimmed to {}.", range, result); } return result; } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java index 8abbde0..a9775da 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ObjectIdentityChecker.java @@ -12,10 +12,12 @@ import org.ovirt.engine.core.common.utils.IObjectDescriptorContainer; import org.ovirt.engine.core.compat.backendcompat.PropertyInfo; import org.ovirt.engine.core.compat.backendcompat.TypeCompat; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ObjectIdentityChecker { + private static final Logger log = LoggerFactory.getLogger(ObjectIdentityChecker.class); + private IObjectDescriptorContainer container; private static Map<String, Class<?>> aliases = new HashMap<String, Class<?>>(); @@ -118,7 +120,7 @@ } } if (!returnValue) { - log.warnFormat("Field {0} can not be updated when status is {1}", name, status); + log.warn("Field '{}' can not be updated when status is '{}'", name, status); } } return returnValue; @@ -146,9 +148,10 @@ dstFld.set(destination, srcFld.get(source)); } } catch (Exception exp) { - log.errorFormat("Failed to copy non editable field {0}, error: {1}", + log.error("Failed to copy non editable field '{}', error: {}", srcFld.getName(), exp.getMessage()); + log.debug("Exception", exp); return false; } } @@ -179,8 +182,8 @@ } for (String fieldName : GetChangedFields(source, destination)) { if (!IsFieldUpdatable(status, fieldName, null, hotsetEnabled)) { - log.warn(String.format("ObjectIdentityChecker.IsUpdateValid:: Not updatable field '%1$s' was updated", - fieldName)); + log.warn("ObjectIdentityChecker.IsUpdateValid:: Not updatable field '{}' was updated", + fieldName); return false; } } @@ -228,6 +231,4 @@ } return returnValue; } - - private static final Log log = LogFactory.getLog(ObjectIdentityChecker.class); } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java index ee91e66..67cb7f8 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OsRepositoryImpl.java @@ -21,8 +21,8 @@ import org.ovirt.engine.core.common.utils.VmDeviceType; import org.ovirt.engine.core.common.businessentities.ArchitectureType; import org.ovirt.engine.core.compat.Version; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This class is holding all Virtual OSs information. @@ -31,7 +31,7 @@ INSTANCE; - private static final Log log = LogFactory.getLog(OsRepositoryImpl.class); + private static final Logger log = LoggerFactory.getLogger(OsRepositoryImpl.class); private static final String OS_ROOT_NODE = "/os/"; private static final String BACKWARD_COMPATIBILITY_ROOT_NODE = "/backwardCompatibility"; /** @@ -59,7 +59,7 @@ buildBackCompatMapping(); validateTree(); if (log.isDebugEnabled()) { - log.debugFormat("Osinfo Repository:\n {0}", toString()); + log.debug("Osinfo Repository:\n {}", toString()); } } @@ -74,12 +74,13 @@ if (derivedFrom != null && !idToUnameLookup.containsValue(derivedFrom)) { idToUnameLookup.remove(Integer.valueOf(id)); preferences.node("/os/" + uniqueName).removeNode(); - log.warn("Illegal parent for os: " + uniqueName); + log.warn("Illegal parent for os '{}'", uniqueName); } } } } catch (BackingStoreException e) { - log.warn("Failed to validate Os Repository due to " + e); + log.warn("Failed to validate Os Repository due to {}", e); + log.debug("Exception", e); throw new RuntimeException("Failed to validate Os Repository due to " + e); } } @@ -595,7 +596,8 @@ try { walkTree(sb, preferences); } catch (BackingStoreException e) { - log.error(e.getStackTrace()); + log.error(e.getMessage()); + log.debug("Exception", e); } return sb.toString(); } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java index 47780e5..23128c9 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/OvfUtils.java @@ -16,18 +16,18 @@ import org.ovirt.engine.core.common.utils.SimpleDependecyInjector; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.utils.archivers.tar.TarInMemoryExport; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.utils.ovf.xml.XmlDocument; import org.ovirt.engine.core.utils.ovf.xml.XmlNode; import org.ovirt.engine.core.utils.ovf.xml.XmlNodeList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class OvfUtils { private final static String TEMPLATE_ENTITY_TYPE = "<TemplateType>"; private final static String ENTITY_NAME = "<Name>"; private final static String END_ENTITY_NAME = "</Name>"; private final static String OVF_FILE_EXT = ".ovf"; - protected final static Log log = LogFactory.getLog(TarInMemoryExport.class); + protected final static Logger log = LoggerFactory.getLogger(TarInMemoryExport.class); private static String getEntityName(String ovfData) { int beginIndexOfEntityName = ovfData.indexOf(ENTITY_NAME) + ENTITY_NAME.length(); int endIndexOfEntityName = ovfData.indexOf(END_ENTITY_NAME, beginIndexOfEntityName); @@ -68,7 +68,7 @@ List<OvfEntityData> ovfEntityDataFromTar = new ArrayList<>(); InputStream is = new ByteArrayInputStream(tar); - log.infoFormat("Start fetching OVF files from tar file"); + log.info("Start fetching OVF files from tar file"); Map<String, ByteBuffer> filesFromTar; try (TarInMemoryExport memoryTar = new TarInMemoryExport(is)) { filesFromTar = memoryTar.unTar(); @@ -86,7 +86,8 @@ XmlDocument xmlDocument = new XmlDocument(ovfData); archType = getOsSection(xmlDocument); } catch (Exception e) { - log.errorFormat("Could not parse architecture type for VM. Exception : {0}", e); + log.error("Could not parse architecture type for VM: {}", e.getMessage()); + log.debug("Exception", e); continue; } // Creates an OVF entity data. @@ -97,17 +98,17 @@ getEntityName(ovfData), archType, getEntityId(fileEntry.getKey())); - log.infoFormat("Retrieve OVF Entity from storage domain ID {0} for entity ID {1}, entity name {2} and VM Type of {3}", + log.info("Retrieve OVF Entity from storage domain ID '{}' for entity ID '{}', entity name '{}' and VM Type of '{}'", storageDomainId, getEntityId(fileEntry.getKey()), getEntityName(ovfData), vmType.name()); ovfEntityDataFromTar.add(ovfEntityData); } else { - log.infoFormat("File {0} is not an OVF file, will be ignored.", fileEntry.getKey()); + log.info("File '{}' is not an OVF file, will be ignored.", fileEntry.getKey()); } } - log.infoFormat("Finish to fetch OVF files from tar file. The number of OVF entities are {0}", + log.info("Finish to fetch OVF files from tar file. The number of OVF entities are {}", ovfEntityDataFromTar.size()); return ovfEntityDataFromTar; } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ResourceUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ResourceUtils.java index 210e104..d6ef0b2 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ResourceUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ResourceUtils.java @@ -5,14 +5,14 @@ import java.io.InputStream; import java.util.Properties; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Provides utilities for handling resource files. */ public class ResourceUtils { - private static final Log log = LogFactory.getLog(ResourceUtils.class); + private static final Logger log = LoggerFactory.getLogger(ResourceUtils.class); /** * Loads a collection of {@link Properties} from a resource file. @@ -41,7 +41,8 @@ is.close(); } catch (Exception e) { String msg = (e.getMessage() != null) ? e.getMessage() : ""; - log.error("Failed to close input stream: " + msg); + log.error("Failed to close input stream: {}", msg); + log.debug("Exception", e); } } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ThreadUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ThreadUtils.java index 189c9e5..c5e8373 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ThreadUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ThreadUtils.java @@ -1,17 +1,18 @@ package org.ovirt.engine.core.utils; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ThreadUtils { - private static final Log log = LogFactory.getLog(ThreadUtils.class); + private static final Logger log = LoggerFactory.getLogger(ThreadUtils.class); public static void sleep(int milliseconds) { try { Thread.sleep(milliseconds); } catch (InterruptedException e) { - log.warn("Interrupted", e); + log.warn("Interrupted: {}", e.getMessage()); + log.debug("Exception", e); } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/TarInMemoryExport.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/TarInMemoryExport.java index 482ef3f..4ad9963 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/TarInMemoryExport.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/archivers/tar/TarInMemoryExport.java @@ -8,11 +8,11 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TarInMemoryExport implements AutoCloseable { - protected final static Log log = LogFactory.getLog(TarInMemoryExport.class); + protected final static Logger log = LoggerFactory.getLogger(TarInMemoryExport.class); private TarArchiveInputStream tarInputStream; @@ -38,7 +38,7 @@ // Read file from the archive into byte array. if (tarInputStream.read(content) == -1) { - log.errorFormat("File {0} could not be read ", tarEntry.getFile()); + log.error("File '{}' could not be read.", tarEntry.getFile()); continue; } fileContent.put(tarEntry.getName(), ByteBuffer.wrap(content)); diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ejb/EJBUtilsStrategy.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ejb/EJBUtilsStrategy.java index 578667d..2564be1 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ejb/EJBUtilsStrategy.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ejb/EJBUtilsStrategy.java @@ -7,8 +7,8 @@ import javax.naming.InitialContext; import javax.naming.NamingException; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * EJBUtils strategy to fine tune the lookup process of beans @@ -17,7 +17,7 @@ */ public abstract class EJBUtilsStrategy { - private static final Log log = LogFactory.getLog(EJBUtilsStrategy.class); + private static final Logger log = LoggerFactory.getLogger(EJBUtilsStrategy.class); // Map from resource types (for example ResourceTypeEnum.DATA_SOURCE ) to // their JNDI names @@ -70,14 +70,14 @@ public <T> T findResource(ContainerManagedResourceType resourceValue) { String jndiNameFromMap = getResourceJNDIName(resourceValue); if (jndiNameFromMap == null) { - log.error("No JNDI name for : " + resourceValue); + log.error("No JNDI name for '{}'", resourceValue); return null; } try { return getReference(jndiNameFromMap); } catch (NamingException ex) { - log.error("Error looking up resource " + resourceValue); + log.error("Error looking up resource '{}'", resourceValue); return null; } } @@ -99,7 +99,7 @@ try { jndiNameFromMap = getBeanJNDIName(beanType); if (jndiNameFromMap == null) { - log.error("No JNDI name for : " + beanType); + log.error("No JNDI name for '{}'", beanType); return null; } @@ -116,17 +116,16 @@ if (context != null) { return getReference(jndiNameSB.toString()); } else { - log.errorFormat("Failed to create InitialContext which is currently null," + - " possibly because given BeanProxyType is null. Given BeanProxyType: {0}", + log.error("Failed to create InitialContext which is currently null," + + " possibly because given BeanProxyType is null. Given BeanProxyType: {}", ((proxyType == null) ? "is null" : proxyType.toString())); throw new NullPointerException(); } } catch (Exception e) { - StringBuilder errorMsgSb = new StringBuilder(); - errorMsgSb.append("Failed to lookup resource type: ").append(beanType).append(". JNDI name: ") - .append(jndiNameSB); - log.error(errorMsgSb.toString(), e); + log.error("Failed to lookup resource type '{}'. JNDI name '{}'. Error: {}", + beanType, jndiNameSB, e.getMessage()); + log.debug("Exception", e); return null; } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java index 9b07410..d45e88d 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/hostinstall/OpenSslCAWrapper.java @@ -12,10 +12,11 @@ import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.utils.EngineLocalConfig; import org.ovirt.engine.core.utils.FileUtil; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class OpenSslCAWrapper { + private static final Logger log = LoggerFactory.getLogger(OpenSslCAWrapper.class); private static String escapeSubjectComponent(String input) { StringBuilder ret = new StringBuilder(); @@ -128,14 +129,15 @@ logOutputAndErrors(outputString, errorString); } else if (exitCode != 0) { returnValue = false; - log.error("Sign Certificate request failed with exit code " + exitCode); + log.error("Sign Certificate request failed with exit code {}", exitCode); logOutputAndErrors(outputString, errorString); } else { log.debug("Successfully completed certificate signing script"); } } } catch (IOException e) { - log.error("Exception signing the certificate", e); + log.error("Exception signing the certificate {}", e.getMessage()); + log.debug("Exception", e); logOutputAndErrors(outputString, errorString); returnValue = false; } @@ -154,7 +156,8 @@ returnString.append(tempString).append('\n'); } } catch (IOException e) { - log.error("IOException while trying to read from buffer", e); + log.error("Exception while trying to read from buffer: {}", e.getMessage()); + log.debug("Exception", e); } return returnString.toString(); } @@ -168,10 +171,10 @@ */ private void logOutputAndErrors(String output, String errors) { if (errors != null && errors.length() != 0) { - log.error("Sign Certificate request script errors:\n" + errors); + log.error("Sign Certificate request script errors:\n {}", errors); } if (output != null && output.length() != 0) { - log.debug("Sign Certificate request script output:\n" + output); + log.debug("Sign Certificate request script output:\n {}", output); } } @@ -181,6 +184,4 @@ protected Runtime getRuntime() { return Runtime.getRuntime(); } - - private static final Log log = LogFactory.getLog(OpenSslCAWrapper.class); } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoader.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoader.java index 1b285bb..607292c 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoader.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/osinfo/OsInfoPreferencesLoader.java @@ -15,8 +15,8 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.common.osinfo.MapBackedPreferences; import org.ovirt.engine.core.utils.OsLoader; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public enum OsInfoPreferencesLoader implements OsLoader { @@ -31,7 +31,7 @@ */ private MapBackedPreferences preferences = new MapBackedPreferences(null, ""); - private Log log = LogFactory.getLog(OsInfoPreferencesLoader.class); + private Logger log = LoggerFactory.getLogger(OsInfoPreferencesLoader.class); public void init(Path directoryPath) { load(directoryPath); @@ -53,13 +53,13 @@ Arrays.sort(files); for (File file : files) { - log.info("Loading file " + file.getPath()); + log.info("Loading file '{}'", file.getPath()); OsinfoPropertiesParser.parse(file.getAbsolutePath()); loadFile(file.toPath()); } } } else { - log.errorFormat("directory {0} doesn't exist.", dir.getPath()); + log.error("Directory '{}' doesn't exist.", dir.getPath()); } } @@ -74,7 +74,8 @@ properties = new Properties(properties); properties.load(reader); } catch (IOException e) { - log.error("Failed loading file " + path); + log.error("Failed loading file '{}': {}", path, e.getMessage()); + log.debug("Exception", e); } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfLogEventHandler.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfLogEventHandler.java index cdb5af4..59dc841 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfLogEventHandler.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfLogEventHandler.java @@ -9,8 +9,8 @@ import org.apache.commons.beanutils.BeanUtils; import org.ovirt.engine.core.common.businessentities.OvfExportOnlyField; import org.ovirt.engine.core.common.businessentities.OvfExportOnlyField.ExportOption; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This class assists in OVF log events handling @@ -18,6 +18,7 @@ * */ public abstract class OvfLogEventHandler<T> { + private static final Logger log = LoggerFactory.getLogger(OvfLogEventHandler.class); // entity to import to OVF or to export from OVF private T entity; @@ -83,7 +84,8 @@ } } catch (Exception ex) { - log.error("Error in initializing the OvfLogHandler", ex); + log.error("Error in initializing the OvfLogHandler: {}", ex.getMessage()); + log.debug("Exception", ex); } } @@ -123,7 +125,8 @@ return map; } catch (Exception ex) { - log.error("Error in getting aliases values map", ex); + log.error("Error in getting aliases values map: {}", ex.getMessage()); + log.debug("Exception", ex); return null; } @@ -147,8 +150,8 @@ Object objValue = typeConverter.convert(value, declaredField.getType()); BeanUtils.setProperty(entity, fieldName, objValue); } catch (Exception ex) { - - log.error("Error filling the entity with values", ex); + log.error("Error filling the entity with values: {}", ex.getMessage()); + log.debug("Exception", ex); } } @@ -188,15 +191,12 @@ } } catch (Exception ex) { - - log.error("Error resseting the log event fields to default values ", ex); + log.error("Error resseting the log event fields to default values: {}", ex.getMessage()); + log.debug("Exception", ex); } } public List<String> getAliases() { return aliases; } - - private static final Log log = LogFactory.getLog(OvfLogEventHandler.class); - } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java index 35cd1b3..f34dfed 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfManager.java @@ -9,13 +9,13 @@ import org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.Version; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.utils.ovf.xml.XmlDocument; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class OvfManager { - private Log log = LogFactory.getLog(OvfManager.class); + private Logger log = LoggerFactory.getLogger(OvfManager.class); public String ExportVm(VM vm, ArrayList<DiskImage> images, Version version) { OvfWriter ovf = new OvfVmWriter(vm, images, version); @@ -66,8 +66,8 @@ } private void logOvfLoadError(String message, String ovfstring) { - log.errorFormat("Error parsing OVF due to {0}", message); - log.debugFormat("Error parsing OVF {0}\n", ovfstring); + log.error("Error parsing OVF due to {}", message); + log.debug("Error parsing OVF {}\n", ovfstring); } public boolean IsOvfTemplate(String ovfstring) throws OvfReaderException { diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfParser.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfParser.java index 56dc1e0..311bc62 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfParser.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/ovf/OvfParser.java @@ -9,14 +9,15 @@ import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.compat.Guid; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.utils.ovf.xml.XmlDocument; import org.ovirt.engine.core.utils.ovf.xml.XmlNamespaceManager; import org.ovirt.engine.core.utils.ovf.xml.XmlNode; import org.ovirt.engine.core.utils.ovf.xml.XmlNodeList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class OvfParser { + private static final Logger log = LoggerFactory.getLogger(OvfParser.class); private static final String utcFallbackDateFormatStr = "yyyy.MM.dd HH:mm:ss"; private static final String utcDateFormatStr = "yyyy/MM/dd HH:mm:ss"; public static final String formatStrFromDiskDescription = "EEE MMM d HH:mm:ss zzz yyyy"; @@ -27,7 +28,8 @@ try { _document = new XmlDocument(ovfstring); } catch (Exception e) { - log.errorFormat("Failed Parsing OVF due to {0} ", e.getMessage()); + log.error("Failed Parsing OVF due to {}", e.getMessage()); + log.debug("Exception", e); throw new OvfReaderException(e); } _xmlNS = new XmlNamespaceManager(); @@ -101,11 +103,10 @@ try { return getDateFormat(utcFallbackDateFormatStr).parse(str); } catch (ParseException e) { - log.error("OVF DateTime format Error, Expected: yyyy/M/dd hh:mm:ss", e); + log.error("OVF DateTime format error: '{}', Expected: yyyy/M/dd hh:mm:ss", e.getMessage()); + log.debug("Exception", e); return null; } } } - - private static final Log log = LogFactory.getLog(OvfParser.class); } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/FenceConfigHelper.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/FenceConfigHelper.java index 1b81d3c..da4b223 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/FenceConfigHelper.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/FenceConfigHelper.java @@ -1,19 +1,19 @@ package org.ovirt.engine.core.utils.pm; +import java.util.HashMap; + import org.apache.commons.lang.StringUtils; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigCommon; import org.ovirt.engine.core.common.config.ConfigValues; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; - -import java.util.HashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FenceConfigHelper { private static HashMap<String, String> keyValidatorMap; private static HashMap<String, String> keyValidatorExampleMap; private static HashMap<String, String> keySeparatorMap; - private static Log log; + private static Logger log = LoggerFactory.getLogger(FenceConfigHelper.class); private static boolean initialized=false; private static final String FenceAgentMappingExpr = "((\\w)+[=](\\w)+[,]{0,1})+"; private static final String FenceAgentDefaultParamsExpr = "([\\w]+([=][\\w]+){0,1}[,]{0,1})+"; @@ -25,7 +25,6 @@ private static void init() { if (!initialized) { - log = LogFactory.getLog(FenceConfigHelper.class); keyValidatorMap = new HashMap<String, String>(); keyValidatorMap.put("FenceAgentMapping", FenceAgentMappingExpr); keyValidatorMap.put("FenceAgentDefaultParams", FenceAgentDefaultParamsExpr); @@ -68,7 +67,8 @@ sb.append(customValue); } else { - log.errorFormat("Configuration key {0} has illegal value {1}. Expression should match {2}", key, customValue, keyValidatorMap.get(key)); + log.error("Configuration key '{}' has illegal value '{}'. Expression should match '{}'", + key, customValue, keyValidatorMap.get(key)); } } return sb.toString(); diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/VdsFenceOptions.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/VdsFenceOptions.java index 7975b79..7bdeedf 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/VdsFenceOptions.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/pm/VdsFenceOptions.java @@ -12,8 +12,8 @@ import org.ovirt.engine.core.common.config.ConfigCommon; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.compat.IntegerCompat; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class VdsFenceOptions implements Serializable { @@ -27,10 +27,10 @@ private static final String FALSE_STRING = "false"; private static final String YES = "yes"; private static final String NO = "no"; - private static final String AGENT_ERROR = "Cannot find fence agent named {0} in fence option mapping"; - private static final String MAPPING_FORMAT_ERROR = "Illegal fencing mapping format {0}"; + private static final String AGENT_ERROR = "Cannot find fence agent named '{}' in fence option mapping"; + private static final String MAPPING_FORMAT_ERROR = "Illegal fencing mapping format '{}'"; - private static final Log log = LogFactory.getLog(VdsFenceOptions.class); + private static final Logger log = LoggerFactory.getLogger(VdsFenceOptions.class); private HashMap<String, HashMap<String, String>> fencingOptionMapping; private static HashMap<String, String> fencingOptionTypes; @@ -95,7 +95,7 @@ } fencingOptionMapping.put(agent, agentOptions); } else { - log.errorFormat(MAPPING_FORMAT_ERROR, agentOptionsStr); + log.error(MAPPING_FORMAT_ERROR, agentOptionsStr); break; } } @@ -131,7 +131,7 @@ result = agentOptions.containsKey(displayedKey) ? agentOptions.get(displayedKey) : displayedKey; } else { - log.errorFormat(AGENT_ERROR, agent); + log.error(AGENT_ERROR, agent); } } return result; @@ -164,7 +164,7 @@ result = realKey; } } else { - log.errorFormat(AGENT_ERROR, agent); + log.error(AGENT_ERROR, agent); } } return result; @@ -432,7 +432,7 @@ HashMap<String, String> agentOptions = fencingOptionMapping.get(agent); result = (agentOptions == null) ? false : agentOptions.containsKey(key); } else { - log.errorFormat(AGENT_ERROR, agent); + log.error(AGENT_ERROR, agent); } return result; @@ -476,7 +476,7 @@ agentOptions.add(pair.getKey()); } } else { - log.errorFormat(AGENT_ERROR, agent); + log.error(AGENT_ERROR, agent); } return agentOptions; diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java index 0d251ab..8a4671e 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/threadpool/ThreadPoolUtil.java @@ -17,12 +17,12 @@ import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.utils.CorrelationIdTracker; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ThreadPoolUtil { - private static final Log log = LogFactory.getLog(ThreadPoolUtil.class); + private static final Logger log = LoggerFactory.getLogger(ThreadPoolUtil.class); private static class InternalThreadExecutor extends ThreadPoolExecutor { @@ -49,12 +49,13 @@ t.setName("org.ovirt.thread." + threadName); } if (log.isDebugEnabled()) { - log.debug("About to run task " + r.getClass().getName() + " from ", new Exception()); + log.debug(String.format("About to run task '%s' from {}", r.getClass().getName()), new Exception()); } if (getQueue().size() > 5) { - log.warn("Executing a command: " + r.getClass().getName() + " , but note that there are " - + getQueue().size() + " tasks in the queue."); + log.warn("Executing a command '{}', but note that there are {} tasks in the queue.", + r.getClass().getName(), + getQueue().size()); } } @@ -186,7 +187,8 @@ } return resultList; } catch (Exception e) { - log.warnFormat("The thread pool failed to execute list of tasks"); + log.warn("The thread pool failed to execute list of tasks: {}", e.getMessage()); + log.debug("Exception", e); throw new RuntimeException(e); } } diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java index 8aa8f40..f09f4cf 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/transaction/TransactionSupport.java @@ -14,12 +14,12 @@ import org.ovirt.engine.core.compat.TransactionScopeOption; import org.ovirt.engine.core.utils.ejb.ContainerManagedResourceType; import org.ovirt.engine.core.utils.ejb.EjbUtils; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TransactionSupport { - private static final Log log = LogFactory.getLog(TransactionSupport.class); + private static final Logger log = LoggerFactory.getLogger(TransactionSupport.class); /** * JBoss specific location of TransactionManager @@ -152,7 +152,7 @@ } catch (RuntimeException rte) { throw rte; } catch (Exception e) { - log.error("executeInRequired - Wrapping Exception: " + e.getClass().getName() + " with RunTimeException"); + log.error("executeInRequired - Wrapping Exception: {} with RunTimeException", e.getClass().getName()); throw new RuntimeException("Failed running code", e); } } @@ -180,7 +180,7 @@ } catch (RuntimeException rte) { throw rte; } catch (Exception e) { - log.error("executeInSuppressed - Wrapping Exception: " + e.getClass().getName() + " with RunTimeException"); + log.error("executeInSuppressed - Wrapping Exception: {} with RunTimeException", e.getClass().getName()); throw new RuntimeException("Failed executing code", e); } return result; @@ -216,8 +216,8 @@ // code failed need to rollback tm.rollback(); log.info("transaction rolled back"); - log.error("executeInNewTransaction - Wrapping Exception: " + e.getClass().getName() - + " with RunTimeException"); + log.error("executeInNewTransaction - Wrapping Exception: {} with RunTimeException", + e.getClass().getName()); throw new RuntimeException("Failed executing code", e); } // commit or rollback according to state diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/RandomUtilsSeedingRule.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/RandomUtilsSeedingRule.java index 51c12bd..1403371 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/RandomUtilsSeedingRule.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/RandomUtilsSeedingRule.java @@ -2,8 +2,8 @@ import org.junit.rules.TestWatcher; import org.junit.runner.Description; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A rule to improve the work with {@link RandomUtils} in unit tests. @@ -16,6 +16,8 @@ * </code> */ public class RandomUtilsSeedingRule extends TestWatcher { + private static final Logger log = LoggerFactory.getLogger(RandomUtilsSeedingRule.class); + private static final String RANDOM_SEED_PROPERTY = "test.random.seed"; @Override @@ -25,13 +27,11 @@ try { seed = Long.parseLong(seedProperty); } catch (NumberFormatException e) { - log.infoFormat("Property \"{0}\" was not set, using System.currentTimeMillis() as a seed.", + log.info("Property '{}' was not set, using System.currentTimeMillis() as a seed.", RANDOM_SEED_PROPERTY); seed = System.currentTimeMillis(); } RandomUtils.instance().setSeed(seed); - log.info("Running test with random seed: " + RandomUtils.instance().getSeed()); + log.info("Running test with random seed: {}", RandomUtils.instance().getSeed()); } - - private static final Log log = LogFactory.getLog(RandomUtilsSeedingRule.class); } diff --git a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/customprop/DevicePropertiesUtilsTest.java b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/customprop/DevicePropertiesUtilsTest.java index 9cdb9bf..1c134c6 100644 --- a/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/customprop/DevicePropertiesUtilsTest.java +++ b/backend/manager/modules/utils/src/test/java/org/ovirt/engine/core/utils/customprop/DevicePropertiesUtilsTest.java @@ -28,15 +28,15 @@ import org.ovirt.engine.core.common.utils.exceptions.InitializationException; import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.utils.MockConfigRule; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Tests for custom device properties handling */ @RunWith(MockitoJUnitRunner.class) public class DevicePropertiesUtilsTest { - private static final Log log = LogFactory.getLog(DevicePropertiesUtilsTest.class); + private static final Logger log = LoggerFactory.getLogger(DevicePropertiesUtilsTest.class); /** * Mock supported cluster levels for custom device properties -- To view, visit http://gerrit.ovirt.org/34264 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0b99ca3947a3ad778601da27decdbad751cfa19c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Martin Peřina <mper...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches