AndroidLogger


Source link: https://github.com/danylovolokh/AndroidLogger

AndroidLogger

This is a lightweight Logger to file for Android. It's based on VoNaLogger

Recommended usage

  • Add this to your build.gradle file of the project.
buildscript {

  repositories {

jcenter()
  
}
 
}
 
  • Add this dependency.
dependencies {

  compile 'com.github.danylovolokh:android-logger:1.0.2' 
}
 
  • Initalize AndroidLogger in your Application class before using it.


  File logsDirectory = AndroidLogger.getDefaultLogFilesDirectory(this);

int logFileMaxSizeBytes = 2 * 1024 * 1024; // 2Mb

try {

 AndroidLogger.initialize(

this,

logsDirectory,

"Log_File_Name",

logFileMaxSizeBytes,

false

);

}
 catch (IOException e) {

 // Some error happened - most likely there is no free space on the system

}
 

To log text to file use AndroidLogger like this.



  AndroidLogger.v("TAG", "Verbose Message");

AndroidLogger.d("TAG", "Debug Message");

AndroidLogger.i("TAG", "Info Message");

AndroidLogger.w("TAG", "Warn Message");

AndroidLogger.e("TAG", "Error Message");
 

NOTE: this will not log the message to LogCat! If you want to log to both LogCat and File you need to create some kind of LoggerWrapper, like this.

public abstract class LoggerWrapper {

 public static int v(final String TAG, final String message) {

Log.v(TAG, message);

return AndroidLogger.v(TAG, message);

  
}

public static int d(final String TAG, final String message) {

Log.d(TAG, message);

return AndroidLogger.d(TAG, message);

  
}

public static int inf(final String TAG, final String message) {

Log.i(TAG, message);

return AndroidLogger.i(TAG, message);

  
}

public static int w(final String TAG, final String message) {

Log.w(TAG, message);

return AndroidLogger.w(TAG, message);

  
}

public static int err(final String TAG, final String message) {

Log.e(TAG, message);

return AndroidLogger.e(TAG, message);

  
}
 
}
 
  • How to get logs. I recommend to use this method:

 // after calling this method AndroidLoger stops receiving new logs so you will need to reinitialize it.
  AndroidLogger.processPendingLogsStopAndGetLogFiles(new AndroidLogger.GetFilesCallback() {

@Override

public void onFiles(File[] logFiles) {

 // get everything you need from these files

 try {

  AndroidLogger.reinitAndroidLogger();

 
}
 catch (IOException e) {

  e.printStackTrace();

 
}

}

  
}
);
 

There are also other options to get logs from file. Please see the source code.

How it works.

Here is a decription from VoNaLogger. Because basically AndroidLogger is jsut a wrapper. The logs (any parameters passed to the logger) are stored in Log Entries. Log Entries are reused because the main goal of this library is to create the smallest amount of objects during writing to file.

License

Copyright 2017 Danylo Volokh

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.

Resources

Animated Pencil Action view for Android.

Markwon is a library for Android that renders markdown as system-native Spannables. It gives ability to display markdown in all TextView widgets (TextView, Button, Switch, CheckBox, etc), Notifications, Toasts, etc. No WebView is required. Library provides reasonable defaults for display style of markdown but also gives all the means to tweak the appearance if desired. All markdown features are supported (including limited support for inlined HTML code, markdown tables and images).

Flubber is an elegant solution for making animations in Android. The library is inspired by the Spring library for iOS. It supports all of the animations, curves and properties that are present in Spring. The library provides an interpolator called Spring which is similar to the iOS CASpringAnimation.

Promise library for JVM and Android based on the Promises/A+ specification from JavaScript.

Persian official calendar convertor.

Support shadow with CircleImageView.

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