package com.microsoft.azure.storage.core;
import org.slf4j.LoggerFactory;
import com.microsoft.azure.storage.OperationContext;
public class Logger {
public static void debug(OperationContext opContext, String format) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isDebugEnabled()) {
logger.debug(formatLogEntry(opContext, format));
}
}
}
public static void debug(OperationContext opContext, String format, Object... args) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isDebugEnabled()) {
logger.debug(formatLogEntry(opContext, format, args));
}
}
}
public static void debug(OperationContext opContext, String format, Object arg1) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isDebugEnabled()) {
logger.debug(formatLogEntry(opContext, format, arg1));
}
}
}
public static void debug(OperationContext opContext, String format, Object arg1, Object arg2) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isDebugEnabled()) {
logger.debug(formatLogEntry(opContext, format, arg1, arg2));
}
}
}
public static void error(OperationContext opContext, String format) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isErrorEnabled()) {
logger.error(formatLogEntry(opContext, format));
}
}
}
public static void error(OperationContext opContext, String format, Object... args) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isErrorEnabled()) {
logger.error(formatLogEntry(opContext, format, args));
}
}
}
public static void error(OperationContext opContext, String format, Object arg1) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isErrorEnabled()) {
logger.error(formatLogEntry(opContext, format, arg1));
}
}
}
public static void error(OperationContext opContext, String format, Object args1, Object args2) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isErrorEnabled()) {
logger.error(formatLogEntry(opContext, format, args1, args2));
}
}
}
public static void info(OperationContext opContext, String format) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isInfoEnabled()) {
logger.info(formatLogEntry(opContext, format));
}
}
}
public static void info(OperationContext opContext, String format, Object... args) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isInfoEnabled()) {
logger.info(formatLogEntry(opContext, format, args));
}
}
}
public static void info(OperationContext opContext, String format, Object arg1) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isInfoEnabled()) {
logger.info(formatLogEntry(opContext, format, arg1));
}
}
}
public static void info(OperationContext opContext, String format, Object arg1, Object arg2) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isInfoEnabled()) {
logger.info(formatLogEntry(opContext, format, arg1, arg2));
}
}
}
public static void trace(OperationContext opContext, String format) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isTraceEnabled()) {
logger.trace(formatLogEntry(opContext, format));
}
}
}
public static void trace(OperationContext opContext, String format, Object... args) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isTraceEnabled()) {
logger.trace(formatLogEntry(opContext, format, args));
}
}
}
public static void trace(OperationContext opContext, String format, Object arg1) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isTraceEnabled()) {
logger.trace(formatLogEntry(opContext, format, arg1));
}
}
}
public static void trace(OperationContext opContext, String format, Object arg1, Object arg2) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isTraceEnabled()) {
logger.trace(formatLogEntry(opContext, format, arg1, arg2));
}
}
}
public static void warn(OperationContext opContext, String format) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isWarnEnabled()) {
logger.warn(formatLogEntry(opContext, format));
}
}
}
public static void warn(OperationContext opContext, String format, Object... args) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isWarnEnabled()) {
logger.warn(formatLogEntry(opContext, format, args));
}
}
}
public static void warn(OperationContext opContext, String format, Object arg1) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isWarnEnabled()) {
logger.warn(formatLogEntry(opContext, format, arg1));
}
}
}
public static void warn(OperationContext opContext, String format, Object arg1, Object arg2) {
if (shouldLog(opContext)) {
org.slf4j.Logger logger = opContext == null ? LoggerFactory.getLogger(OperationContext.defaultLoggerName)
: opContext.getLogger();
if (logger.isWarnEnabled()) {
logger.warn(formatLogEntry(opContext, format, arg1, arg2));
}
}
}
public static boolean shouldLog(OperationContext opContext) {
if (opContext != null) {
return opContext.isLoggingEnabled();
}
else {
return OperationContext.isLoggingEnabledByDefault();
}
}
private static String formatLogEntry(OperationContext opContext, String format) {
return String.format("{%s}: {%s}", (opContext == null) ? "*" : opContext.getClientRequestID(),
format.replace('\n', '.'));
}
private static String formatLogEntry(OperationContext opContext, String format, Object... args) {
return String.format("{%s}: {%s}", (opContext == null) ? "*" : opContext.getClientRequestID(),
String.format(format, args).replace('\n', '.'));
}
private static String formatLogEntry(OperationContext opContext, String format, Object arg1) {
return String.format("{%s}: {%s}", (opContext == null) ? "*" : opContext.getClientRequestID(),
String.format(format, arg1).replace('\n', '.'));
}
private static String formatLogEntry(OperationContext opContext, String format, Object arg1, Object arg2) {
return String.format("{%s}: {%s}", (opContext == null) ? "*" : opContext.getClientRequestID(),
String.format(format, arg1, arg2).replace('\n', '.'));
}
private Logger() {
}
}