All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.adjust.sdk.Logger Maven / Gradle / Ivy
//
// Logger.java
// Adjust
//
// Created by Christian Wellenbrock on 2013-04-18.
// Copyright (c) 2013 adjust GmbH. All rights reserved.
// See the file MIT-LICENSE for copying permission.
//
package com.adjust.sdk;
import android.util.Log;
import java.util.Arrays;
import java.util.Locale;
import static com.adjust.sdk.Constants.LOGTAG;
public class Logger implements ILogger {
private LogLevel logLevel;
private boolean logLevelLocked;
private static String formatErrorMessage = "Error formating log message: %s, with params: %s";
public Logger() {
setLogLevel(LogLevel.INFO);
logLevelLocked = false;
}
@Override
public void setLogLevel(LogLevel logLevel) {
if (logLevelLocked) {
return;
}
this.logLevel = logLevel;
}
@Override
public void setLogLevelString(String logLevelString) {
if (null != logLevelString) {
try {
setLogLevel(LogLevel.valueOf(logLevelString.toUpperCase(Locale.US)));
} catch (IllegalArgumentException iae) {
error("Malformed logLevel '%s', falling back to 'info'", logLevelString);
}
}
}
@Override
public void verbose(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.VERBOSE) {
try {
Log.v(LOGTAG, String.format(Locale.US, message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(Locale.US, formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void debug(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.DEBUG) {
try {
Log.d(LOGTAG, String.format(Locale.US, message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(Locale.US, formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void info(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.INFO) {
try {
Log.i(LOGTAG, String.format(Locale.US, message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(Locale.US, formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void warn(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.WARN) {
try {
Log.w(LOGTAG, String.format(Locale.US, message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(Locale.US, formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void error(String message, Object... parameters) {
if (logLevel.androidLogLevel <= Log.ERROR) {
try {
Log.e(LOGTAG, String.format(Locale.US, message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(Locale.US, formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void Assert(String message, Object... parameters) {
if(logLevel.androidLogLevel <= Log.ASSERT) {
try {
Log.println(Log.ASSERT, LOGTAG, String.format(Locale.US, message, parameters));
} catch (Exception e) {
Log.e(LOGTAG, String.format(Locale.US, formatErrorMessage, message, Arrays.toString(parameters)));
}
}
}
@Override
public void lockLogLevel() {
logLevelLocked = true;
}
}