Giter Site home page Giter Site logo

logcat's Introduction

LogCat

The library project includes classes for writing an app logs in Android. Is essentially a wrapper for the standard Android Log class. The main difference is the automatically check the current log's level while trying to write logs. Also, there is a possibility to change the log level for the application at runtime via adb.

LogCat class

This class extends standard Android API for sending a log output. It allows you to create log messages (similarly android.util.Log class). Generally, you should use the following LogCat methods, listed in order from the highest to lowest priority (or, least to most verbose):

  • LogCat.e() (ERROR)
  • LogCat.w() (WARN)
  • LogCat.i() (INFO)
  • LogCat.d() (DEBUG)
  • LogCat.v() (VERBOSE)

You should never compile VERBOSE logs into your app, except during development. DEBUG logs are compiled in but stripped at runtime, while ERROR, WARN and INFO logs are always kept.

Before using this class for writing logs, you should initialize it and specify the main log tag for your app (further APP_TAG). This tag will be used into all methods for print logs as unique log tag. This is the one of main difference between the class LogCat and Android android.util.Log.

Tip: A good conventions are to use the app name as the main log tag and to declare an appropriate constant for this tag in your app class, for example:

private static final String APP_TAG = "MyApp";

Then you could use this constant in method LogCat.init(String).

The LogCat class allows you to use different log tags for various components in your code (classes, methods and etc.) in addition to the main log tag for your app (as example APP_TAG).A good convention is to declare a TAG constant in your class:

private static final String TAG = "MyActivity";

and use that in subsequent calls to the log methods. This tag will be added to LogCat message:

 LogCat.d(TAG, "Any message.");
 Output: "D/MyApp: MyActivity: Any message."

You could change log level for your app using main app log tag. The default level of any tag is set to INFO. This means that any level above and including INFO will be logged. You can change the default level by setting a system property:

adb shell setprop log.tag.[APP_TAG] [LEVEL]

Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS. SUPPRESS will turn off all logging for your tag. You can also create a local.prop file that with the following in it:

log.tag.[APP_TAG]=[LEVEL]

and place that in /data/local.prop.

Tip: Don't forget to change log level for main app log tag to DEBUG via shell command, or you could specify debug flag during initialization, for example:

LogCat.init(APP_TAG, BuildConfig.DEBUG);

Threads

You could use LogCat class for printing information about active threads. This information printed as usual app log, and you could specify tag and priority.

StackTrace

You could use LogCat class for printing a stack trace. The stack trace information printed as usual app log, and you could specify tag and priority.

MemoryInfo

You could use LogCat class for printing information about memory usage. The information printed as usual app log, and you could specify tag and priority.

License

Copyright (C) 2013 Mikhail Malakhov <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

logcat's People

Contributors

malakhv avatar

Stargazers

 avatar Vr Floppa avatar Kirill Shalnov avatar

Watchers

James Cloos avatar  avatar  avatar

logcat's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.