Bulk Emailing

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 27 July 2010

Custom Logger for Android

Posted on 00:14 by Unknown
Now and then you must feel the need to have some more control over the way Android Application logs are getting displayed. Possible requirement scenarios; redirecting your Android logs into a File or you might want to control the logs those are getting displayed e.g. for production mode, you may want to block all logs to get better performance.
I have written a custom Logger, which is a wrapper over android.util.Log. This will keep existing behavior of Log class as it is and add few handy features to get more control over your application logs-
Storing Logs directly into File- at present all logs comes on the LogCat. You need to manually copy/past logs from LogCat to any file for further analysis. Another option is to get the Dump state when an application gets “Forced Closed”. But this wrapper will allow you an automatic solution. Imagine a scenario, your Phone is not connected with the LogCat and you need the tracing. This wrapper will be helpful in this scenario.
Controlled Logging- it will give you the control to select the range of logs to be display/stored e.g. if you select the allowed Log Level to VERBOSE, all Log Level (integer values) higher than VERBOSE will be displayed. You can even completely block all logging (perfect for production).
To get above additional benefits, you need to refer to a new Class instead of android.util.Log-
MLog.i(“TAG”, “ Log Message”)
All methods are static and make sure, you call MLog.init(context, “ Log_File_Name”) at the very beginning (probably in the onCreate() method of your Activity). This utility class will create a log file under data/data/ Your_Application_Package/files/ Log_File_Name
Sample usage scenarios-
Step1- Configure the Logger (Optional Step)
To stop logging-
MLog.enableLog = false; (this will be suitable for Production Release)
To enable logging only of INFO, WARN and ERROR-
MLog.logLevel = MLog.INFO;
Step2- Initialize the Logger
Once you set above properties, initiate the logger-
MLog.init(this.getApplicationContext(), "app_log.txt");
Note: be careful to pass Application Context rather than Activity Context, which might cause Leak Window issue.
Step3- Use the Logger. Same as you use Log.i(TAG, msg), Log.v(TAG, msg)
MLog.i(TAG, "Location Activity...");
So now you can get these additional benefits by using the attached Logger (MLog.java) in your next project. Have a happy and controlled logging :-)
  
Email ThisBlogThis!Share to XShare to Facebook
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Weekend at Yeouido (Han River Cruise)
    Yeouido is one of the Han River Cruise boarding points. It has a wonderful river side park (Yeouido P...
  • CityWeather
    Update: Release 1.1 has been uploaded. It will now provide weekly forecast of your selected cities. Download   CityWeather is an Android...
  • Few Multi-Threading Implementations
    Sequential Producer & Consumer In my first example, I will demonstrate an implementation to solve ...
  • Accessing Yahoo Finance API
    Since last few days I was wondering the right set of Web Service to read Country wise Stock Exchange index information . I found a bunch of ...
  • Regular Expression in JavaScript
    I was struggling to get familiar with JavaScript's Regular expression handling and thought my learning might help others. Here I'll...
  • Alphanumeric Random Number
    Sometime basic things becomes tricky :-) Was trying to find out ways to generate some alphanumeric random number whose size (i.e. number of ...
  • Binary Search Tree in Java
    This post is a part of my continuous effort to just implement few of the important data structures in ...
  • QuickSort in Java
    This post is a part of my continuous effort to just implement few of the important data structures in Java. Please find my previous post on ...
  • InDroid- Access to Android's Hidden API
    I have started one project " InDroid " to expose and share Hidden and Internal methods and variables of Android platform which are...
  • Image Geo Tagging for Android
    " onMap " is an Image Geo Tagging application, which can read EXIF header of images stored in your Android device and Map them ov...

Blog Archive

  • ►  2013 (6)
    • ►  September (2)
    • ►  May (1)
    • ►  April (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2012 (4)
    • ►  July (2)
    • ►  March (1)
    • ►  January (1)
  • ►  2011 (11)
    • ►  November (1)
    • ►  October (2)
    • ►  August (1)
    • ►  June (1)
    • ►  April (2)
    • ►  March (3)
    • ►  January (1)
  • ▼  2010 (27)
    • ►  December (2)
    • ►  November (3)
    • ►  September (2)
    • ►  August (4)
    • ▼  July (4)
      • Custom Logger for Android
      • Weekend at Yeouido (Han River Cruise)
      • A day at Suwon World Cup Stadium
      • Few Multi-Threading Implementations
    • ►  June (7)
    • ►  May (5)
Powered by Blogger.

About Me

Unknown
View my complete profile