Android Open Source - android-gskbyte-utils Logger






From Project

Back to project page android-gskbyte-utils.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project android-gskbyte-utils 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

/*******************************************************************************
 * Copyright (c) 2013 Jose Alcal Correa.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * /*  w  ww .  j  ava  2s .c o  m*/
 * Contributors:
 *     Jose Alcal Correa - initial API and implementation
 ******************************************************************************/
package org.gskbyte.util;

/**
 * Logger class that simplifies the usage of {@link android.util.Log}.
 * 
 * Allows to configure globally if messages with info and debug levels will be
 * printed.
 * 
 * I know that some of this class' methods do not follow my convention of starting static methods
 * with Uppercase, but it's just to make it more similar to android.util.Log.
 * 
 * Both versions are provided.
 * */
public final class Logger
{    
public static boolean LOG_INFO    = true;
public static boolean LOG_DEBUG   = true;

/**
 * Log an info message, if LOG_INFO is enabled.
 * @param tag The log tag.
 * @param message The message to print.
 * */
public static void info(String tag, String message)
{
    if(LOG_INFO) {
        android.util.Log.i(tag, message);
    }
}

/**
 * Log an info message, if LOG_INFO is enabled.
 * @param clazz The caller's class, whose simpleName will be used as tag.
 * @param message The message to print.
 * */
public static void info(Class<?> clazz, String message)
{ info(clazz.getSimpleName(), message); }


/**
 * Log a debug message, if LOG_DEBUG is enabled.
 * @param tag The log tag.
 * @param message The message to print.
 * */
public static void debug(String tag, String message)
{
    if(LOG_INFO) {
        android.util.Log.d(tag, message);
    }
}

/**
 * Log a debug message, if LOG_DEBUG is enabled.
 * @param clazz The caller's class, whose simpleName will be used as tag.
 * @param message The message to print.
 * */
public static void debug(Class<?> clazz, String message)
{ debug(clazz.getSimpleName(), message); }

/**
 * Log an error message
 * @param tag The log tag.
 * @param message The message to print.
 * */
public static void error(String tag, String message)
{
    if(LOG_INFO) {
        android.util.Log.e(tag, message);
    }
}
/**
 * Log an error message.
 * @param clazz The caller's class, whose simpleName will be used as tag.
 * @param message The message to print.
 * */
public static void error(Class<?> clazz, String message)
{ error(clazz.getSimpleName(), message); }

/**
 * Log an error message generated by an exception.
 * @param tag The log tag.
 * @param e The exception whose message will be printed.
 * */
public static void except(String tag, Throwable e, String p_prefix)
{
    String realPrefix = "";
    if(p_prefix!=null && p_prefix.length()>0) {
        realPrefix = p_prefix + " |";
    }
    
    android.util.Log.e(tag, realPrefix + "["+e.getClass().getName()+"] " + " ~> "+e.getMessage());
}

/**
 * Log an error message generated by an exception.
 * @param clazz The caller's class, whose simpleName will be used as tag.
 * @param e The exception whose message will be printed.
 * */
public static void except(Class<?> clazz, Throwable e, String prefix)
{ except(clazz.getSimpleName(), e, prefix); }

/**
 * Log an error message generated by an exception.
 * @param tag The log tag.
 * @param e The exception whose message will be printed.
 * */
public static void except(String tag, Throwable e)
{ except(tag, e, ""); }

/**
 * Log an error message generated by an exception.
 * @param clazz The caller's class, whose simpleName will be used as tag.
 * @param e The exception whose message will be printed.
 * */
public static void except(Class<?> clazz, Throwable e)
{ except(clazz, e, ""); }

/**
 * Utility method to start a time measurement. Returns a long value with the current time millis.
 * This can be used later in logTimeMeasurement()
 * @return the integer id used to log the time
 * */
public static synchronized long startTimeMeasurement()
{ return System.currentTimeMillis(); }

/**
 * Given the a long millis value (for example, given by startTimeMeasurement), logs the time passed between now and the given time.
 * Logs are printed using debug level, so they depend on LOG_DEBUG's value
 * @param startMillis The time when the measurement started
 * @param tag The log tag.
 * @param messagePrefix The base message to print with the format #message -> #time ms
 * @return the computed time difference, in milliseconds
 * */
public static synchronized long logTimeMeasurement(long startMillis, String tag, String messagePrefix)
{
    final long differenceMillis = System.currentTimeMillis()-startMillis;
    debug(tag, messagePrefix + " ~> " + differenceMillis + " ms");
    return differenceMillis;
}

/**
 * Given the a long millis value (for example, given by startTimeMeasurement), logs the time passed between now and the given time.
 * Logs are printed using debug level, so they depend on LOG_DEBUG's value
 * @param timeId The time id provided previously by startTimeMeasurement()
 * @param clazz The caller's class, whose simpleName will be used as tag.
 * @param messagePrefix The base message to print with the format #message -> #time ms
 * @return the computed time difference, in milliseconds
 * */
public static synchronized long logTimeMeasurement(long startMillis, Class<?> clazz, String messagePrefix)
{ return logTimeMeasurement(startMillis, clazz.getSimpleName(), messagePrefix); }

}




Java Source Code List

com.woozzu.android.widget.IndexScroller.java
com.woozzu.android.widget.IndexableListView.java
org.gskbyte.FragmentWrapperActivity.java
org.gskbyte.animation.ExpandAnimation.java
org.gskbyte.bitmap.AbstractBitmapManager.java
org.gskbyte.bitmap.BitmapColorizer.java
org.gskbyte.bitmap.BitmapManager.java
org.gskbyte.bitmap.CachedBitmapColorizer.java
org.gskbyte.bitmap.IndexedBitmaps.java
org.gskbyte.bitmap.LRUBitmapCache.java
org.gskbyte.bitmap.LRUBitmapManager.java
org.gskbyte.bitmap.PrivateBitmapManager.java
org.gskbyte.bitmap.ReferencedBitmaps.java
org.gskbyte.collection.ArrayHashMap.java
org.gskbyte.collection.DoubleSparseArray.java
org.gskbyte.collection.ListHashMap.java
org.gskbyte.dialog.DownloadDialogFragment.java
org.gskbyte.dialog.LoadDialogFragment.java
org.gskbyte.dialog.OpenLinkDialogBuilder.java
org.gskbyte.dialog.PickerDialogFragment.java
org.gskbyte.download.DiskDownload.java
org.gskbyte.download.DownloadManager.java
org.gskbyte.download.Download.java
org.gskbyte.download.MemoryDownload.java
org.gskbyte.drawable.AutoBackgroundButtonDrawable.java
org.gskbyte.listener.IListenable.java
org.gskbyte.listener.ListenableNG.java
org.gskbyte.listener.Listenable.java
org.gskbyte.preferences.DialogSeekBarPreference.java
org.gskbyte.preferences.InlineSeekBarPreference.java
org.gskbyte.remote.AsyncURLRequest.java
org.gskbyte.remote.URLRequest.java
org.gskbyte.tasks.QueuedTaskExecutor.java
org.gskbyte.tasks.TaskStep.java
org.gskbyte.tasks.Task.java
org.gskbyte.ui.ArrayAdapterWithDefaultValue.java
org.gskbyte.ui.ListAdapter.java
org.gskbyte.ui.ColorDialog.ColorDialog.java
org.gskbyte.ui.ColorDialog.ColorPreference.java
org.gskbyte.ui.iconifiedMainMenuList.EntryView.java
org.gskbyte.ui.iconifiedMainMenuList.MainMenuAdapter.java
org.gskbyte.ui.iconifiedMainMenuList.MenuEntry.java
org.gskbyte.util.FrequentIntents.java
org.gskbyte.util.IOUtils.java
org.gskbyte.util.Logger.java
org.gskbyte.util.OpenFileHandlerFactory.java
org.gskbyte.util.OpenFileHandler.java
org.gskbyte.util.XmlUtils.java
org.gskbyte.view.AsyncImageView.java
org.gskbyte.view.AutoBackgroundButton.java
org.gskbyte.view.AutoBackgroundImageButton.java
org.gskbyte.view.AutoHeightImageView.java
org.gskbyte.view.ExpandedGridView.java
org.gskbyte.view.ExpandedListView.java
org.gskbyte.view.FontUtil.java
org.gskbyte.view.FontableButton.java
org.gskbyte.view.FontableCheckBox.java
org.gskbyte.view.FontableEditText.java
org.gskbyte.view.FontableTextView.java
org.gskbyte.view.FullWidthImageView.java
org.gskbyte.view.ProportionalHeightLayout.java
org.gskbyte.view.PullToRefreshListView.java
org.gskbyte.view.SquaredLayout.java
org.gskbyte.view.StepSeekBar.java
org.gskbyte.view.TextViewUtil.java
org.gskbyte.view.ViewUtils.java