AndroidLogger
Android Library that makes debugging, log collection, filtering and analysis easier.
Contains 2 modules:
- Logger: 'com.github.ShiftHackZ.AndroidLogger:logger:1.0'
- LoggerKit: 'com.github.ShiftHackZ.AndroidLogger:logger-kit:1.0' (optional)
Logger
Core Logger library which implements main logic of log collecting and log processing mechanisms.
Implementation
- In project-level gradle add new maven repository:
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
- In app-level gradle add new implementation:
dependencies { implementation 'com.github.ShiftHackZ.AndroidLogger:logger:1.0' }
Components
- Logger: main component for configuration and log collecting;
- LoggerPrinter: interface that describes log output contract;
- LoggerMiddleware: interface that describes log processing.
Usage example
-
Optional: Implement some class that extends from LoggerMiddleware interface (see this example);
-
Add your middleware during runtime. It is recommended to do this in onCreate() method of your main Application class.
class LoggerApp : Application() { override fun onCreate() { super.onCreate() Logger.addMiddleware(LoggerNetworkMiddleware(this)) } }
- Collect logs like usual, by using Logger static methods (instead of system Log methods).
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Logger.d(this::class, "onCreate", "Hello World!") } }
LoggerKit
Extra LoggerKit library, which depends on Logger core library, and adds much more functionality to logger.
It is not necessary to use LoggerKit, you may use just Logger core library with your custom LoggerMiddleware.
Implementation
In app-level gradle add implementation:
dependencies { implementation 'com.github.ShiftHackZ.AndroidLogger:logger-kit:1.0' }
There is no need to implement Logger core 'com.github.ShiftHackZ.AndroidLogger:logger', it will be included by gradle automatically.
Components
- LoggerKit: main component of Kit library, extends functionality of Logger, duplicates some of it's methods for configuration;
- DatabaseLoggerMiddleware: built in middleware that collects logs and saves entries in local database;
- Also LoggerKit contains view components which allows to view and manage logs during runtime.
Screenshots
Usage example
-
Optional: Implement some class that extends from LoggerMiddleware interface (see this example);
-
Initialize LoggerKit, if needed add your middleware. LoggerKit must be initialized in onCreate() method of your main Application class.
class LoggerApp : Application() { override fun onCreate() { super.onCreate() LoggerKit.addMiddleware(LoggerNetworkMiddleware(this)) .initialize(this) } }
- Collect logs like usual, by using Logger static methods (instead of system Log methods).
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Logger.d(this::class, "onCreate", "Hello World!") } }
- You can view your logs by calling LoggerKit.openLogViewer() during runtime.
class SettingsActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) binding.btnLogs.setOnClickListener { LoggerKit.openLogViewer() } } }
Credits
- Developer: Dmitriy Moroz
- E-Mail: [email protected]