Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/conf/log4j-cloud.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ under the License.
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<throwableRenderer class="com.cloud.utils.log.CglibThrowableRenderer"/>
<throwableRenderer class="org.apache.cloudstack.utils.log.CglibThrowableRenderer"/>

<!-- ================================= -->
<!-- Preserve messages in a local file -->
Expand Down
7 changes: 4 additions & 3 deletions utils/src/main/java/com/cloud/utils/AutoCloseableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
// under the License.
package com.cloud.utils;

import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Logger;
import org.apache.cloudstack.utils.log.LogFactory;

public class AutoCloseableUtil {
private final static Logger s_logger = Logger.getLogger(AutoCloseableUtil.class);
private final static Logger LOG = LogFactory.getLogger(AutoCloseableUtil.class);

public static void closeAutoCloseable(AutoCloseable ac, String message) {
try {
Expand All @@ -29,7 +30,7 @@ public static void closeAutoCloseable(AutoCloseable ac, String message) {
}

} catch (Exception e) {
s_logger.warn("[ignored] " + message, e);
LOG.warn("[ignored] " + message, e);
}
}

Expand Down
7 changes: 4 additions & 3 deletions utils/src/main/java/com/cloud/utils/EncryptionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Logger;
import org.apache.cloudstack.utils.log.LogFactory;
import org.jasypt.encryption.pbe.PBEStringEncryptor;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

import com.cloud.utils.exception.CloudRuntimeException;

public class EncryptionUtil {
public static final Logger s_logger = Logger.getLogger(EncryptionUtil.class.getName());
public static final Logger LOG = LogFactory.getLogger(EncryptionUtil.class);
private static PBEStringEncryptor encryptor;

private static void initialize(String key) {
Expand Down Expand Up @@ -66,7 +67,7 @@ public static String generateSignature(String data, String key) {
final byte[] encryptedBytes = mac.doFinal();
return Base64.encodeBase64String(encryptedBytes);
} catch (NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException e) {
s_logger.error("exception occurred which encoding the data." + e.getMessage());
LOG.error("exception occurred which encoding the data." + e.getMessage());
throw new CloudRuntimeException("unable to generate signature", e);
}
}
Expand Down
11 changes: 6 additions & 5 deletions utils/src/main/java/com/cloud/utils/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

package com.cloud.utils;

import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Logger;
import org.apache.cloudstack.utils.log.LogFactory;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
Expand All @@ -29,7 +30,7 @@

public class HttpUtils {

public static final Logger s_logger = Logger.getLogger(HttpUtils.class);
public static final Logger LOG = LogFactory.getLogger(HttpUtils.class);

public static final String UTF_8 = "UTF-8";
public static final String RESPONSE_TYPE_JSON = "json";
Expand Down Expand Up @@ -81,12 +82,12 @@ public static void writeHttpResponse(final HttpServletResponse resp, final Strin
addSecurityHeaders(resp);
resp.getWriter().print(response);
} catch (final IOException ioex) {
if (s_logger.isTraceEnabled()) {
s_logger.trace("Exception writing http response: " + ioex);
if (LOG.isTraceEnabled()) {
LOG.trace("Exception writing http response: " + ioex);
}
} catch (final Exception ex) {
if (!(ex instanceof IllegalStateException)) {
s_logger.error("Unknown exception writing http response", ex);
LOG.error("Unknown exception writing http response", ex);
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions utils/src/main/java/com/cloud/utils/Journal.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import java.util.ArrayList;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Level;
import org.apache.cloudstack.utils.log.Logger;

/**
* Journal is used to kept what has happened during a process so someone can track
Expand Down Expand Up @@ -91,14 +91,18 @@ public String toString() {
public static class LogJournal extends Journal {
Logger _logger;

@Deprecated
public LogJournal(String name, org.apache.log4j.Logger logger) {
this(name, new Logger(logger));
}
public LogJournal(String name, Logger logger) {
super(name);
_logger = logger;
}

@Override
public void record(String msg, Object... params) {
record(_logger, Level.DEBUG, msg, params);
record(_logger, (org.apache.cloudstack.utils.log.Level)Level.DEBUG, msg, params);
}
}
}
9 changes: 5 additions & 4 deletions utils/src/main/java/com/cloud/utils/LogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,24 @@

import java.io.File;

import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Logger;
import org.apache.cloudstack.utils.log.LogFactory;
import org.apache.log4j.xml.DOMConfigurator;

public class LogUtils {
public static final Logger s_logger = Logger.getLogger(LogUtils.class);
public static final Logger LOG = LogFactory.getLogger(LogUtils.class);

public static void initLog4j(String log4jConfigFileName) {
assert (log4jConfigFileName != null);
File file = PropertiesUtil.findConfigFile(log4jConfigFileName);
if (file != null) {
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
LOG.info("log4j configuration found at " + file.getAbsolutePath());
DOMConfigurator.configureAndWatch(file.getAbsolutePath());
} else {
String nameWithoutExtension = log4jConfigFileName.substring(0, log4jConfigFileName.lastIndexOf('.'));
file = PropertiesUtil.findConfigFile(nameWithoutExtension + ".properties");
if (file != null) {
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
LOG.info("log4j configuration found at " + file.getAbsolutePath());
DOMConfigurator.configureAndWatch(file.getAbsolutePath());
}
}
Expand Down
13 changes: 7 additions & 6 deletions utils/src/main/java/com/cloud/utils/ProcessUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
import javax.naming.ConfigurationException;

import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Logger;
import org.apache.cloudstack.utils.log.LogFactory;

import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;

public class ProcessUtil {
private static final Logger s_logger = Logger.getLogger(ProcessUtil.class.getName());
private static final Logger LOG = LogFactory.getLogger(ProcessUtil.class);

// paths cannot be hardcoded
public static void pidCheck(String pidDir, String run) throws ConfigurationException {
Expand All @@ -43,7 +44,7 @@ public static void pidCheck(String pidDir, String run) throws ConfigurationExcep
try {
final File propsFile = PropertiesUtil.findConfigFile("environment.properties");
if (propsFile == null) {
s_logger.debug("environment.properties could not be opened");
LOG.debug("environment.properties could not be opened");
} else {
final Properties props = PropertiesUtil.loadFromFile(propsFile);
dir = props.getProperty("paths.pid");
Expand All @@ -52,7 +53,7 @@ public static void pidCheck(String pidDir, String run) throws ConfigurationExcep
}
}
} catch (IOException e) {
s_logger.debug("environment.properties could not be opened");
LOG.debug("environment.properties could not be opened");
}

final File pidFile = new File(dir + File.separator + run);
Expand All @@ -68,7 +69,7 @@ public static void pidCheck(String pidDir, String run) throws ConfigurationExcep
}
try {
final long pid = Long.parseLong(pidLine);
final Script script = new Script("bash", 120000, s_logger);
final Script script = new Script("bash", 120000, LOG);
script.add("-c", "ps -p " + pid);
final String result = script.execute();
if (result == null) {
Expand All @@ -86,7 +87,7 @@ public static void pidCheck(String pidDir, String run) throws ConfigurationExcep
}
pidFile.deleteOnExit();

final Script script = new Script("bash", 120000, s_logger);
final Script script = new Script("bash", 120000, LOG);
script.add("-c", "echo $PPID");
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
script.execute(parser);
Expand Down
2 changes: 1 addition & 1 deletion utils/src/main/java/com/cloud/utils/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ public String toString() {

return "Done. Duration: " + getDurationInMillis() + "ms";
}
}
}
11 changes: 6 additions & 5 deletions utils/src/main/java/com/cloud/utils/PropertiesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
import java.util.Properties;
import java.util.Set;

import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Logger;
import org.apache.cloudstack.utils.log.LogFactory;

public class PropertiesUtil {
private static final Logger s_logger = Logger.getLogger(PropertiesUtil.class);
private static final Logger LOG = LogFactory.getLogger(PropertiesUtil.class);

/**
* Searches the class path and local paths to find the config file.
Expand Down Expand Up @@ -129,7 +130,7 @@ public static void loadFromJar(Properties properties, String configFile) throws
if (stream != null) {
properties.load(stream);
} else {
s_logger.error("Unable to find properties file: " + configFile);
LOG.error("Unable to find properties file: " + configFile);
}
}

Expand All @@ -144,15 +145,15 @@ public static Map<String, String> processConfigFile(String[] configFiles) {
try {
loadFromFile(preProcessedCommands, commandsFile);
} catch (IOException ioe) {
s_logger.error("IO Exception loading properties file", ioe);
LOG.error("IO Exception loading properties file", ioe);
}
}
else {
// in case of a file within a jar in classpath, try to open stream using url
try {
loadFromJar(preProcessedCommands, configFile);
} catch (IOException e) {
s_logger.error("IO Exception loading properties file from jar", e);
LOG.error("IO Exception loading properties file from jar", e);
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions utils/src/main/java/com/cloud/utils/ReflectUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Logger;
import org.apache.cloudstack.utils.log.LogFactory;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
import org.reflections.util.ClasspathHelper;
Expand All @@ -50,8 +51,8 @@

public class ReflectUtil {

private static final Logger s_logger = Logger.getLogger(ReflectUtil.class);
private static final Logger logger = Logger.getLogger(Reflections.class);
private static final Logger LOG = LogFactory.getLogger(ReflectUtil.class);
private static final Logger logger = LogFactory.getLogger(Reflections.class);

public static Pair<Class<?>, Field> getAnyField(Class<?> clazz, String fieldName) {
try {
Expand Down Expand Up @@ -186,13 +187,13 @@ private static List<String> flattenProperties(final Object target, final Class<?
return unmodifiableList(serializedProperties);

} catch (IntrospectionException e) {
s_logger.warn("Ignored IntrospectionException when serializing class " + target.getClass().getCanonicalName(), e);
LOG.warn("Ignored IntrospectionException when serializing class " + target.getClass().getCanonicalName(), e);
} catch (IllegalArgumentException e) {
s_logger.warn("Ignored IllegalArgumentException when serializing class " + target.getClass().getCanonicalName(), e);
LOG.warn("Ignored IllegalArgumentException when serializing class " + target.getClass().getCanonicalName(), e);
} catch (IllegalAccessException e) {
s_logger.warn("Ignored IllegalAccessException when serializing class " + target.getClass().getCanonicalName(), e);
LOG.warn("Ignored IllegalAccessException when serializing class " + target.getClass().getCanonicalName(), e);
} catch (InvocationTargetException e) {
s_logger.warn("Ignored InvocationTargetException when serializing class " + target.getClass().getCanonicalName(), e);
LOG.warn("Ignored InvocationTargetException when serializing class " + target.getClass().getCanonicalName(), e);
}

return emptyList();
Expand Down Expand Up @@ -222,8 +223,8 @@ public static ClassLoader getClassLoaderForName(final String name) {
final List<URL> searchUrls = new ArrayList<>();
for (final URL url: urls) {
if (url.toString().contains(name)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Search URL: " + url.toString());
if (LOG.isDebugEnabled()) {
LOG.debug("Search URL: " + url.toString());
}
searchUrls.add(url);
}
Expand Down
7 changes: 4 additions & 3 deletions utils/src/main/java/com/cloud/utils/SwiftUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Hex;
import org.apache.log4j.Logger;
import org.apache.cloudstack.utils.log.Logger;
import org.apache.cloudstack.utils.log.LogFactory;

import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script;

public class SwiftUtil {
private static Logger logger = Logger.getLogger(SwiftUtil.class);
private static Logger logger = LogFactory.getLogger(SwiftUtil.class);
protected static final long SWIFT_MAX_SIZE = 5L * 1024L * 1024L * 1024L;
private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
private static final String CD_SRC = "cd %s;";
Expand Down Expand Up @@ -309,4 +310,4 @@ private static String getMeta(Map<String, String> metas) {
}
return cms.toString();
}
}
}
Loading