GithubHelp home page GithubHelp logo

android_log's Introduction

Android Log

Support lazy generate log message. And prevent log output for release applications.

See also:

Get Start

  1. Add jitpack repository to root build.gradle:

    allprojects {
        repositories {
            maven { url 'https://jitpack.io' }
        }
    }
  2. Add library dependency to project's build.gradle:

    dependencies {
        implementation 'com.github.VerstSiu:android_log:1.0'
    }

Usage

  1. Use from log manager factory:

    val log = LogManagerFactory.simple()
    
    log.i("test_message", "Hello World!")
  2. Use from common:

    val log = SimpleLog
    
    log.i("test_message", "Hello World!")
  3. Customize log handler:

    val handler = object: LogHandler {
      override fun dispatch(level: Int, tag: String, message: String, error: Throwable?) {
        println(message)
      }
    }
    val log = LogManagerFactory.simple(handler)
    
    log.i("test_message", "Hello World!")
  4. Trim text contents:

    log.i("http", "response text: ${responseText.trimLimit(300)}")

API List

  • Log handler:

    interface LogHandler {
      fun dispatch(level: Int, tag: String, message: String, error: Throwable?)
    }
  • Simple log manager:

    class SimpleLogManager {
      fun v(tag: String, message: String[, error: Throwable?])
      fun d(tag: String, message: String[, error: Throwable?])
      fun i(tag: String, message: String[, error: Throwable?])
      fun w(tag: String, message: String[, error: Throwable?])
      fun e(tag: String, message: String[, error: Throwable?])
      fun wtf(tag: String, message: String[, error: Throwable?])
    }
  • Tag fix log manager:

    class TagFixLogManager {
      fun v(message: String[, error: Throwable?])
      fun d(message: String[, error: Throwable?])
      fun i(message: String[, error: Throwable?])
      fun w(message: String[, error: Throwable?])
      fun e(message: String[, error: Throwable?])
      fun wtf(message: String[, error: Throwable?])
    }
  • Lazy log manager:

    class LazyLogManager {
      fun v(tag: String, [error: Throwable?, ]getMessage: () -> String)
      fun d(tag: String, [error: Throwable?, ]getMessage: () -> String)
      fun i(tag: String, [error: Throwable?, ]getMessage: () -> String)
      fun w(tag: String, [error: Throwable?, ]getMessage: () -> String)
      fun e(tag: String, [error: Throwable?, ]getMessage: () -> String)
      fun wtf(tag: String, [error: Throwable?, ]getMessage: () -> String)
    }
  • Tag fix lazy log manager:

    class TagFixLazyLogManager {
      fun v([error: Throwable?, ]getMessage: () -> String)
      fun d([error: Throwable?, ]getMessage: () -> String)
      fun i([error: Throwable?, ]getMessage: () -> String)
      fun w([error: Throwable?, ]getMessage: () -> String)
      fun e([error: Throwable?, ]getMessage: () -> String)
      fun wtf([error: Throwable?, ]getMessage: () -> String)
    }
  • Log manager factory:

    object LogManagerFactory {
      fun simple([handler: LogHandler]): SimpleLogManager
      fun simple(tag: String[, handler: LogHandler]): TagFixLogManager
      fun lazy([handler: LogHandler]): LazyLogManager
      fun lazy(tag: String[, handler: LogHandler]): TagFixLazyLogManager
    }
  • Common log manager:

    object SimpleLog: SimpleLogManager
    object LazyLog: LazyLogManager
  • Extend methods:

    fun String.trimLimit(length: Int): String

License


   Copyright(c) 2018 VerstSiu

   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.

android_log's People

Contributors

verstsiu avatar

Watchers

 avatar

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.