log


Source link: https://github.com/zserge/log

Ultimately minimal (yet very convenient) logger for Android and Java.

Log is a super-simple drop-in replacement for android.util.Log that can also be used in normal Java projects.

Features

// API is backwards-compatible with android.util.Log, so you already know it. Log.d(tag, "X equals " + x);
  // Safe logging for multiple comma-separated values Log.d(tag, "X", x)  // Tag is optional, by default it equals to the class name  class Foo {
  public void foo() {

Log.d("Hello");
 // prints 'D/Foo: Hello'  
}
 
}
  // If tag or TAG field is found - it overrides the class name class Foo {
  private final static String tag = "Bar";  public void foo() {

Log.d("Hello");
 // prints 'D/Bar: Hello'  
}
 
}
  // And it's still compatible with your old code class Foo {
  private final static String TAG = "Bar";  public void foo() {

Log.d(TAG, "Hello");
 // prints 'D/Bar: Hello', not 'D/Bar: Bar Hello'  
}
 
}
  // Even if you used different tag field names class Foo {
  static {

Log.useTags(new String[]{
"tag", "TAG", "MYTAG", "_TAG", "iLoveLongFieldName"
}
);
  
}
  private final static String _TAG = "Bar";  ... 
}
  // Support for Throwables Exception e = new Exception("foo");
 Log.d("Something bad happened", someObject, "error:", e);
 // A log message and a stack trace will be printed  // Chainable API Log  .d("First")  .d("Second")  .d("Third line")  // Filters by log level Log.level(Log.I);
 Log.d("foo");
 // will be ignored  // Format strings are suported, too Log.useFormat(true);
 Log.d("X equals %d", x);
 // prints 'X equals 42' // But if no format is provided - log will be printed as multiple values Log.d("Value of X", x);
 // prints 'Value of X 42'  // Long messages are wrapped on newlines // If the message doesn't contain newlines and is longer than 4000 symbols // (like compact JSONs or HTML) - it will be wrapped on whitespace or punctuation Log.d("Hello\nworld");
 // prints 'D/SomeTag: Hello' and 'D/SomeTag: world'  // On Android logs are printed via android.util.Log by default. // On other JVMs logs are printed via System.out.println by default. // Unless specified otherwise Log.usePrinter(Log.SYSTEM, true).usePrinter(Log.ANDROID, false).d("hello");
 // will be printed via System.out on Android as well Log.usePrinter(mMyPrinter, true);
 // or you can use your own custom printers  // If you want to disable debug printing for Release build if (!BuildConfig.DEBUG) {

Log.usePrinter(Log.ANDROID, false);
 // from now on Log.d etc do nothing and is likely to be optimized with JIT 
}
  // And it's only a single class of 200 LOC, so don't be afraid that it will // bloat your APK or slow down your builds.

Installation

build.gradle:

repositories {
  jcenter() // mavenCentral() would work, too 
}
 dependencies {
  compile 'co.trikita:log:1.1.5' 
}

Migration from android.util.Log

If you already have a big project and want to use this logger right now - you can just change imports using 'sed' (Linux/Mac/Cygwin):

$ find -name "*.java" -type f -exec sed -i 's/import android.util.Log/import trikita.log.Log/g' {

}
 \;

If you're using Android Studio: in the project pane right-click on the app/java directory (or any other directory containing your java classes). In the popup menu select "Replace in Path..." option.

'Text to find' should be "android.util.Log". 'Replace with' should be "trikita.log.Log". Click Find, click All files.

If you know an easier way (or for different IDE) - let me know.

How is it different from...

Here is a list of other popular loggers for Android: https://android-arsenal.com/tag/57

Most of them are too specific (logging to file or socket, or printing logs on screen). Some of them are too complicated (Twig, SLF4J and every other logger that has factories). But some of them are really nice, so that my logger was inspired by them.

These loggers are simple and put class and method names into the log message automatically. However they only support a single string parameter so you will end up with "X = "+x+", y="+y in most of your logs.

This two are very similar to my logger, but the first one is a bit bloated and the both don't support comma-separated values, only format-like strings:

And of course there are Jake Wharton's hugo and timber. Hugo is nice, but I didn't need to log/profile my methods, I only need to print log messages from time to time.

Timber was my favourite choice, but I don't use it because of the name. I understand that it's really clever, but my hands are too much used to start log lines with the letter "L", not "T". And timber also doesn't support comma-separated values, only format strings.

License

Code is distributed under MIT License

Resources

RecyclerView adapter classes for managing multiple view types.

An Android grid lock screen view with a callback interface. It is very simple to use.

Kotlin library for Android with useful extensions to eliminate boilerplate code in Android SDK and focus on productivity.

SoBitmap is a bitmap decode library for Android. Developers can customize max size of memory, max memory size for output bitmap and picture size, then SoBitmap will do its best for producing the right bitmap.

ADP

Android Distribution Platform (ADP) is a fullstack framework for storing, distributing and installing versionized apk files based (mostly for internal team or roll-back purposes) on each CI git commit.

Twine is a command line tool for managing your strings and their translations. These strings are all stored in a master text file and then Twine uses this file to import and export strings in a variety of file types, including iOS and Mac OS X .strings files, Android .xml files, gettext .po files, and [jquery-localize][jquerylocalize] .json files.

This allows individuals and companies to easily share strings across multiple projects, as well as export strings in any format the user wants.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes