Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:25:30+00:00 2026-06-17T10:25:30+00:00

Update: Reformulated the question and header: I always thought that expensive android Logging methods

  • 0

Update: Reformulated the question and header:

I always thought that expensive android Logging methods can be optimized by asking if logging is active like this

    import android.util.Log;

    if (Log.isLoggable("MyContext", Log.DEBUG))
    {
        Log.d("MyContext", "my logging: " + callExpensiveCalculation());
    }

However when trying this with the android 2.2 emulator my Log.d() is never called.

So i tried this code

    Log.v(MY_CONTEXT, "VERBOSE logging is active: " + Log.isLoggable(MY_CONTEXT, Log.VERBOSE));
    Log.d(MY_CONTEXT, "DEBUG logging is active: " + Log.isLoggable(MY_CONTEXT, Log.DEBUG));
    Log.i(MY_CONTEXT, "INFO logging is active: " + Log.isLoggable(MY_CONTEXT, Log.INFO));
    Log.w(MY_CONTEXT, "WARN logging is active: " + Log.isLoggable(MY_CONTEXT, Log.WARN));
    Log.e(MY_CONTEXT, "ERROR logging is active: " + Log.isLoggable(MY_CONTEXT, Log.ERROR));

and to my surprise i got

02-27 19:05:43.015: V/MyContext(334): VERBOSE logging is active: false
02-27 19:05:43.015: D/MyContext(334): DEBUG logging is active: false
02-27 19:05:43.015: I/MyContext(334): INFO logging is active: true
02-27 19:05:43.015: W/MyContext(334): WARN logging is active: true
02-27 19:05:43.015: E/MyContext(334): ERROR logging is active: true

so logging works even if logging is disabled.
Is this a bug in android or in my test-code?

Is there an other way to find out if debugging (or one of the other loglevels) is active or not?

I use eclipse logcat-view with log-level verbose and started the test from eclipse with run as android-app

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:25:32+00:00Added an answer on June 17, 2026 at 10:25 am

    isLoggable is really just a mechanism to provide a flag for certain tags for your convenience. It doesn’t actually do anything to disable logging. Your first block of code is correct:

    if (Log.isLoggable("MyContext", Log.DEBUG))
    {
        Log.d("MyContext", "my logging: " + callExpensiveCalculation());
    }
    

    This will log or not log depending on if isLoggable returns true or false. However, when you do this (without checking isLoggable):

    Log.d(MY_CONTEXT, "DEBUG logging is active: " + Log.isLoggable(MY_CONTEXT, Log.DEBUG));
    

    It will log regardless of what isLoggable would have returned had you called it. In short, you need to do that check everywhere that you log if you want to enable/disable logging based on that flag. The if statement is the part that lets you skip unnecessary logs. If the if clause is false, the code inside is never run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update IV / Current status: I've now confirmed trough another question that the character
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
UPDATE UPI_ATTRIBUTE SET SITE_INC ='0' WHERE USER_PROFILING_NAME IN ('CAR_IMPLICIT','CAR_EXPLICIT') Above is my query that
UPDATE 6/21/12 I have a form in rails that is working similar to an
Update : I found almost exact similar question , yet it has slightly different
UPDATE: Added doGet function. I have a web app that is used for a
UPDATE : Martin R below has provided a very clear (and succinct!) answer that
UPDATE: I now have a solution I'm much happier with that, whilst not solving
UPDATE users SET field = my_sp() in SQL Server 2005. Apparently I can't do
UPDATE: It was suggested in the comments that I create a wiki for this.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.