Android Open Source - protohipster T Log






From Project

Back to project page protohipster.

License

The source code is released under:

Apache License

If you think the Android project protohipster listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.flipper83.protohipster.globalutils.module;
/* ww  w .  j av  a  2s .  co m*/
import java.util.Arrays;

import javax.inject.Inject;

import android.content.Context;
import android.util.Log;
import android.widget.Toast;

import com.flipper83.protohipster.globalutils.interfaces.Logger;


/**
 * Real Logger 
 **/
 class TLog implements Logger {

    public static final Boolean TLOG_ENABLED = true;


    private static class Singleton {
        static final TLog INSTANCE = new TLog();
    }

    public static Logger getLogger() {
        return Singleton.INSTANCE;
    }

    // API Level: supported values
    private static final String LEVEL_INFO = "0";
    private static final String LEVEL_ERROR = "1";
    private static final String LEVEL_DEBUG = "2";
    private static final String LEVEL_WARNING = "3";

    protected Config logConfig;

    public TLog(Config logConfig) {
        this.logConfig = logConfig;
    }

    @Inject
    public TLog() {
        this(new Config());
    }

    // Verbose
    public void v(String tag, String msg) {
        if (isVerboseEnabled()) {
            Log.v(tag + getThreadId(), msg);
        }

    }

    public void v(String tag, String msg, Throwable tr) {
        if (isVerboseEnabled()) {
            Log.v(tag + getThreadId(), msg + '\n' + Log.getStackTraceString(tr));
        }
    }

    // Debug
    /**
     * Adds a <b>debug</b> log.<br>
     * This level of logging should be used to further note what is happening on
     * the device that could be relevant to investigate and debug unexpected
     * behaviors.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     */
    public void d(String tag, String msg) {
        d(tag, msg, false);
    }

    /**
     * Adds a <b>debug</b> log. As optional, it can send a report. <br>
     * This level of logging should be used to further note what is happening on
     * the device that could be relevant to investigate and debug unexpected
     * behaviors.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param report
     *            - true, if a report has to be sent; false, otherwise.
     */
    public void d(String tag, String msg, boolean report) {
        if (isDebugEnabled()) {
            Log.d(tag + getThreadId(), msg);
        }
        if (report) {
            sendReport(tag, msg, LEVEL_DEBUG, new Exception("Crash Report: " + msg));
        }

    }

    /**
     * Adds a <b>debug</b> log. <br>
     * This level of logging should be used to further note what is happening on
     * the device that could be relevant to investigate and debug unexpected
     * behaviors.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param tr
     *            - exception
     */
    public void d(String tag, String msg, Throwable tr) {
        d(tag, msg, tr, false);
    }

    /**
     * Adds a <b>debug</b> log. As optional, it can send a report.<br>
     * This level of logging should be used to further note what is happening on
     * the device that could be relevant to investigate and debug unexpected
     * behaviors.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param tr
     *            - exception
     * @param report
     *            - true, if a report has to be sent; false, otherwise.
     */
    public void d(String tag, String msg, Throwable tr, boolean report) {
        if (isDebugEnabled()) {
            Log.d(tag + getThreadId(), msg + '\n' + Log.getStackTraceString(tr));
        }
        if (report) {
            sendReport(tag, msg, LEVEL_DEBUG, tr);
        }
    }

    // Info
    /**
     * Adds an <b>informative</b> log. <br>
     * This level of logging should used be to note that something interesting
     * to most people happened
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     */
    public void i(String tag, String msg) {
        i(tag, msg, false);
    }

    /**
     * Adds an <b>informative</b> log. As optional, it can send a report.<br>
     * This level of logging should used be to note that something interesting
     * to most people happened
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param report
     *            - true, if a report has to be sent; false, otherwise.
     */
    public void i(String tag, String msg, boolean report) {
        if (isInfoEnabled()) {
            Log.i(tag, msg);
        }
        if (report) {
            sendReport(tag, msg, LEVEL_INFO, new Exception("Crash Report: " + msg));
        }
    }

    /**
     * Adds an <b>informative</b> log.<br>
     * This level of logging should used be to note that something interesting
     * to most people happened
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param tr
     *            - exception
     */
    public void i(String tag, String msg, Throwable tr) {
        i(tag, msg, tr, false);
    }

    /**
     * Adds an <b>informative</b> log. As optional, it can send a report.<br>
     * This level of logging should used be to note that something interesting
     * to most people happened
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param tr
     *            - exception
     * @param report
     *            - true, if a report has to be sent; false, otherwise.
     */
    public void i(String tag, String msg, Throwable tr, boolean report) {
        if (isInfoEnabled()) {
            Log.i(tag, msg + '\n' + Log.getStackTraceString(tr));
        }
        if (report) {
            sendReport(tag, msg, LEVEL_INFO, tr);
        }
    }

    // error
    /**
     * Adds an <b>error</b> log. This method will send a report to the server.<br>
     * This level of logging should be used when something fatal has happened.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     */
    public void e(String tag, String msg) {
        e(tag, msg, false);
    }

    /**
     * Adds an <b>error</b> log. As optional, it can send a report.<br>
     * This level of logging should be used when something fatal has happened.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param report
     *            - true, if a report has to be sent; false, otherwise.
     */
    public void e(String tag, String msg, boolean report) {
        if (isErrorEnabled()) {
            Log.e(tag, msg);
        }
        if (report) {
            sendReport(tag, msg, LEVEL_ERROR, new Exception("Crash Report: " + msg));
        }
    }

    /**
     * Adds an <b>error</b> log. This method will send a report to the server.<br>
     * This level of logging should be used when something fatal has happened.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param tr
     *            - exception
     */
    public void e(String tag, String msg, Throwable tr) {
        e(tag, msg, tr, true);
    }

    /**
     * Adds an <b>error</b> log. As optional, it can send a report.<br>
     * This level of logging should be used when something fatal has happened.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param tr
     *            - exception
     * @param report
     *            - true, if a report has to be sent; false, otherwise.
     */
    public void e(String tag, String msg, Throwable tr, boolean report) {
        if (isErrorEnabled()) {
            Log.e(tag, msg + '\n' + Log.getStackTraceString(tr));
        }
        if (report) {
            sendReport(tag, msg, LEVEL_ERROR, tr);
        }
    }

    // warning
    /**
     * Adds a <b>warning</b> log. <br>
     * This level of logging should used when something serious and unexpected
     * happened
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     */
    public void w(String tag, String msg) {
        w(tag, msg, false);
    }

    /**
     * Adds a <b>warning</b> log. As optional, it can send a report.<br>
     * This level of logging should used when something serious and unexpected
     * happened
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param report
     *            - true, if a report has to be sent; false, otherwise.
     */
    public void w(String tag, String msg, boolean report) {
        if (isInfoEnabled()) {
            Log.w(tag, msg);
        }
        if (report) {
            sendReport(tag, msg, LEVEL_WARNING, new Exception("Crash Report: " + msg));
        }

    }

    // Force report
    /**
     * This level of logging should be used when a weird behavior happens and we
     * want the user to send us a comment to help us to figure out why that
     * happened.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     */
    public void r(final String tag, final String msg) {
        r(tag, msg, new Exception("Crash Report: " + msg));

    }

    /**
     * This level of logging should be used when a weird behavior happens and we
     * want the user to send us a comment to help us to figure out why that
     * happened.
     *
     * @param tag
     *            - LOG tag
     * @param msg
     *            - message
     * @param tr
     *            - exception
     */
    public void r(final String tag, final String msg, final Throwable tr) {
        Log.e(tag, msg + '\n' + Log.getStackTraceString(tr));

    }

    /**
     * Sends a crash report.
     *
     * @param tag
     * @param msg
     *            - message
     * @param level
     *            - type of information being stored. Values supported are: <li>
     *            0 = info <li>1 = error <li>2 = debug <li>3 = warning
     * @param tr
     */
    private void sendReport(String tag, String msg, String level, Throwable tr) {

    }

    // Performance recording
    public void p(String tag, long time) {
        // Performance recording
        if (isDebugEnabled())
            Log.i(tag + getThreadId(), "Performance - Total time: " + time + "ms");
    }

    public void p(String tag, String msg, long time) {
        // Performance recording
        if (isDebugEnabled())
            Log.i(tag + getThreadId(), "Performance - " + msg + " - Total time: " + time + "ms");
    }

    public void pt(String tag, String msg, long time) {
        // Performance recording
        if (isDebugEnabled())
            Log.i(tag + getThreadId(), "Performance - " + msg + " - Total time: " + (System.currentTimeMillis() - time)
                    + "ms");
    }

    public void t(Context context, String tag, String msg) {
        if (isVerboseEnabled())
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }

    public void t(Context context, String msg) {
        if (isVerboseEnabled())
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }

    public void tr(String tag, String msg) {
        if (isDebugEnabled())
            Log.i(tag, "Trace: " + msg + " : " + getCalledFrom());
    }

    public String getCalledFrom() {
        StackTraceElement caller = Thread.currentThread().getStackTrace()[4];
        return caller.getClassName() + "." + caller.getMethodName() + ":" + caller.getLineNumber();
    }

    public boolean isDebugEnabled() {
        return logConfig.minimumLogLevel <= Log.DEBUG;
    }

    public boolean isVerboseEnabled() {
        return logConfig.minimumLogLevel <= Log.VERBOSE;
    }

    public boolean isInfoEnabled() {
        return logConfig.minimumLogLevel <= Log.INFO;
    }

    public boolean isErrorEnabled() {
        return logConfig.minimumLogLevel <= Log.ERROR;
    }

    public Config getConfig() {
        return logConfig;
    }

    public String getCallStack() {
        StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
        return Arrays.toString(stackTraceElements);
    }

    // Config class
    public static class Config {
        protected int minimumLogLevel = TLOG_ENABLED ? Log.VERBOSE : Log.ERROR;

        protected Config() {
        }

        public int getLoggingLevel() {
            return minimumLogLevel;
        }

        public void setLoggingLevel(int level) {
            minimumLogLevel = level;
        }
    }

    private String getThreadId() {
        return " - " + String.valueOf(Thread.currentThread().getId());
    }
}




Java Source Code List

com.flipper83.protohipster.daggerUtils.ForApplication.java
com.flipper83.protohipster.feed.datasource.api.Api.java
com.flipper83.protohipster.feed.datasource.api.call.ApiCall.java
com.flipper83.protohipster.feed.datasource.api.call.parse.GetLikesCall.java
com.flipper83.protohipster.feed.datasource.api.call.parse.LikeUserCall.java
com.flipper83.protohipster.feed.datasource.api.call.parse.ParseLikeTableDefinitions.java
com.flipper83.protohipster.feed.datasource.api.call.parse.response.GetLikesResponse.java
com.flipper83.protohipster.feed.datasource.api.call.rest.ApiRestCall.java
com.flipper83.protohipster.feed.datasource.api.call.rest.GetFeedCall.java
com.flipper83.protohipster.feed.datasource.api.call.rest.request.GetFeedRequest.java
com.flipper83.protohipster.feed.datasource.api.call.rest.response.GetFeedResponse.java
com.flipper83.protohipster.feed.datasource.api.callback.ApiResponseCallback.java
com.flipper83.protohipster.feed.datasource.api.model.UserApiEntry.java
com.flipper83.protohipster.feed.datasource.api.model.UserApiName.java
com.flipper83.protohipster.feed.datasource.api.model.UserApi.java
com.flipper83.protohipster.feed.datasource.interfaces.LikeDataSource.java
com.flipper83.protohipster.feed.datasource.interfaces.UserDataSource.java
com.flipper83.protohipster.feed.datasource.interfaces.callbacks.GetCountLikesCallback.java
com.flipper83.protohipster.feed.datasource.interfaces.callbacks.GetMyLikersCallback.java
com.flipper83.protohipster.feed.datasource.interfaces.callbacks.GetUserCallback.java
com.flipper83.protohipster.feed.datasource.interfaces.callbacks.LikeUserCallback.java
com.flipper83.protohipster.feed.datasource.module.DataSourceModule.java
com.flipper83.protohipster.feed.datasource.module.LikeDataSourceParse.java
com.flipper83.protohipster.feed.datasource.module.UserDataSourceImp.java
com.flipper83.protohipster.feed.datasource.module.api.ApiParse.java
com.flipper83.protohipster.feed.datasource.module.api.ApiRest.java
com.flipper83.protohipster.feed.domain.boundaries.FeedBoundary.java
com.flipper83.protohipster.feed.domain.boundaries.HipsterBoundary.java
com.flipper83.protohipster.feed.domain.boundaries.VotesBoundary.java
com.flipper83.protohipster.feed.domain.gateway.Hipster.java
com.flipper83.protohipster.feed.domain.interactors.GetFeed.java
com.flipper83.protohipster.feed.domain.interactors.GetMyLikers.java
com.flipper83.protohipster.feed.domain.interactors.LikeHipster.java
com.flipper83.protohipster.feed.domain.mappers.HipsterMapperManual.java
com.flipper83.protohipster.feed.domain.mappers.HipsterMapper.java
com.flipper83.protohipster.feed.domain.module.DomainModule.java
com.flipper83.protohipster.feed.domain.module.GetFeedImpl.java
com.flipper83.protohipster.feed.domain.module.GetMyLikersImpl.java
com.flipper83.protohipster.feed.domain.module.LikeHipsterImp.java
com.flipper83.protohipster.feed.view.module.FeedViewModule.java
com.flipper83.protohipster.feed.view.provider.FeedProvider.java
com.flipper83.protohipster.feed.view.ui.FeedAdapter.java
com.flipper83.protohipster.feed.view.ui.HipsterListFragment.java
com.flipper83.protohipster.feed.view.ui.ProtoActivity.java
com.flipper83.protohipster.feed.view.viewmodel.FeedViewModel.java
com.flipper83.protohipster.feed.view.viewmodel.HipsterViewModel.java
com.flipper83.protohipster.feed.view.viewmodel.mapper.HipsterViewMapperManual.java
com.flipper83.protohipster.feed.view.viewmodel.mapper.HipsterViewMapper.java
com.flipper83.protohipster.globalutils.cache.Cache.java
com.flipper83.protohipster.globalutils.cache.implementations.MapKeysCache.java
com.flipper83.protohipster.globalutils.interfaces.Logger.java
com.flipper83.protohipster.globalutils.module.AndroidModule.java
com.flipper83.protohipster.globalutils.module.GlobalModule.java
com.flipper83.protohipster.globalutils.module.LoggerProvider.java
com.flipper83.protohipster.globalutils.module.TLog.java
com.flipper83.protohipster.globalutils.rating.RatingCalculatorFiveStars.java
com.flipper83.protohipster.globalutils.rating.RatingCalculator.java
com.flipper83.protohipster.uibase.app.ProtoApplication.java
com.flipper83.protohipster.uibase.base.BaseActivity.java
com.flipper83.protohipster.uibase.base.BaseFragment.java
com.flipper83.protohipster.uibase.transformation.TransformationBuilder.java
com.flipper83.protohipster.uibase.transformation.privates.RoundAvatarTransformation.java
com.flipper83.protohipster.uibase.transformation.privates.TransformationBuilderPicasso.java