GithubHelp home page GithubHelp logo

emojilog's Introduction

emojilog

Extensible emoji powered logger of anything. Written in Kotlin for the lols.

Getting started

This repository is hosted via jitpack since it's by far the easiest delivery method while also being pretty transparent to the developer.

Make sure you have added jitpack to the list of your repositories:

maven("https://jitpack.io")

Then simply add the emojilog dependency

dependencies {
    compile("com.github.vishna:emojilog:master-SNAPSHOT")
}

Example usage

import dev.vishna.emojilog.std.defaultLogger // default logger
import dev.vishna.emojilog.android.* // predefined "android" like extensions

val log = defaultLogger()

log.info.."Hello world!" // prints: โ„น๏ธ Hello world!
log.error..IllegalStateException("Whoops!") // prints: ๐Ÿ’ฅ Whoops!
log.wtf..IllegalStateException("๐Ÿ’ฉ hit the fan") // prints: ๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ ๐Ÿ’ฉ hit the fan!

Defining own log extensions

val Log.shrug
  get() = { "๐Ÿคท" } lvl "shrug"

NOTE: "shrug" here is a key by which this extension will be cached by the Log instance

If you would want to do some "extra something" with the output e.g. style the color of the text, you can pass extra parameter of Any type as a pair

val Log.fail
  get() = { "โŒ" to 0xFF0000 } lvl "fail"

NOTE: This won't magically create colored text for you, you will need to handle this in your own, custom logger.

{Using closure} to avoid evaluating expression whenever the getter is getting called ๐Ÿ˜‰

Defining own logger

Here's how you could integrate emojilog in your Android App

Log { level, any ->
    val throwable = any as? Throwable
    with(level.log) {
        when (level) {
            verbose -> android.util.Log.v(level.value, "$any")
            debug -> android.util.Log.i(level.value, "$any")
            info -> android.util.Log.i(level.value, "$any")
            warn -> android.util.Log.w(level.value, "$any", throwable)
            error -> android.util.Log.e(level.value, "$any", throwable)
            wtf -> android.util.Log.wtf(level.value, "$any", throwable)
            else -> android.util.Log.d(level.value, "$any")
        }
    }
}

Screenshot 2019-07-17 at 14 24 46

...if only Android's logcat supported emojis ๐Ÿ˜ญ

More examples

Please check out tests ๐Ÿ‘‰ LogTest

Acknowledgments

While creating this library I wasn't aware of Emoji-Log by ahmadawais. The scope of that project is different and focuses on formatting of git commit messages while this one is meant to be logger for simple pet projects written in Kotlin. Anyway, as a tribute to his project, I added git extensions and some tests for it.

๐Ÿบ Cheers!

emojilog's People

Contributors

vishna 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.