Code Monkey home page Code Monkey logo

kalev's Introduction

Kalev

Maven Central

Kalev is a structured logger for JVM (Java, Kotlin etc)

The idea of Kalev is pretty similar to Timber. Library provides Kalevipoeg interface with which you may implement various behaviour for log entries reaction.

Packages

kalev-lib provides pure JVM implementation. Doesn't contains any implementation of Kalevipoeg
kalev-android contains bridge between Kalev and Android's log system. PrintPoeg format log entry as JSON string and print it to LogCat.
kalev-okhttp provide interceptor for okhttp to log network requests in Kalev-way

Usage

Two easy steps:

  1. Add any Kalevipoeg instances you want on application start. In Android application onCreate is a most suitable place
  2. Call Kalev's static methods everywhere throughout your app.

Check full Android sample at sample dir

Fields

Kalev encourages careful, structured logging through logging fields instead of long, unparseable error messages. For example, instead of: Log.e("Failed to send event %s to topic %s with key %d", userEvent, selectedTopic, eventKey), you should log the much more discoverable:

Kalev.with("event", userEvent)
    .with("key", eventKey)
    .with("topic", selectedTopic)
    .e("Failed to send event")

Note, that with call is optional

Level logging

Kalev provides 5 levels of logs: verbose, debug, info, warning and error.

Kalev.v("Fragment created")
Kalev.v(throwable, "Fragment wasn't added")

Kalev.d("User logged in")
Kalev.d(throwable, "User error")

Kalev.i("Added item to bucket")
Kalev.i(throwable, "Busket is full")

Kalev.w("Paying for order")
Kalev.w(throwable, "Failed to pay")

Kalev.e("Smth happens")
Kalev.e(throwable, "Smth happened")

Entries

Besides the fields added with with some fields are automatically added to all logging events:

severity The logging level. E.g. i.
timestamp The timestamp when the entry was created.
message The logging message passed to {v, d, i, w, e} after the with call. E.g. Failed to send event.

Network Logging

Add LoggingInterceptor to your OkHttpClient to log network requests in Kalev-way. Examples of network logs:

http://httpbin.org/get?id=42

{
  "message": "network",
  "method": "GET",
  "path": "\/get",
  "id": "42",
  "response.code": 200,
  "response.body": {
    "args": {
      "id": "42"
    },
    "headers": {
      "Accept-Encoding": "gzip",
      "Content-Type": "application\/json",
      "Host": "httpbin.org",
      "User-Agent": "okhttp\/3.12.12",
      "X-Amzn-Trace-Id": "Root=1-5ed772b8-71eaec363ea2adcca9201200"
    },
    "url": "https:\/\/httpbin.org\/get?id=42"
  }
}

http://httpbin.org/unknown

{
  "message": "network",
  "method": "GET",
  "path": "\/unknown",
  "id": "42",
  "response.code": 404,
  "response.body": "<!DOCTYPE HTML PUBLIC \"-\/\/W3C\/\/DTD HTML 3.2 Final\/\/EN\">\n<title>404 Not Found<\/title>\n<h1>Not Found<\/h1>\n<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.<\/p>\n"
}

FastLog

Kalev creates new object for every log entry which may abuse performance in case of stream of entries. You can go around of this issue with FastLog.

FastLog usage

There is FastLog interface which describes fast logger.
kalev-lib provides SystemFastLog implementation which prints messages to standard output stream
kalev-android provides AndroidFastLog implementation which prints messages to Android's LogCat

Initialisation:

Kalev.fastLog = AndroidFastLog()

Logging

Kalev.fastLog?.v("Activity created")

Gradle

Add this to your dependencies block.

implementation 'eu.bolt:kalev:$latest'

To use an android extension use this dependency instead:

implementation 'eu.bolt:kalev-android:$latest'

Kalev-okhttp package:

implementation 'eu.bolt:kalev-okhttp:$latest'

Naming

Kaleva - also known as Kalevi or Kalev - and his sons are important heroic figures in Estonian, Finnish and Karelian mythology. Wiki

License

MIT License

Copyright (c) 2020 Bolt Technologies OÜ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

kalev's People

Contributors

devindi avatar uladzimir-akulovich avatar

Stargazers

miffa avatar VST Plugins Blog (PT-BR) avatar 邵彬 avatar Jan Stoltman avatar Manasa Murali avatar Junaid Ahmad avatar Vadim avatar Madis Pink avatar Metehan Toksoy avatar Metehan Toksoy avatar

Watchers

Vadim avatar Michał Nowotka avatar James Cloos avatar Daria Ryazhskikh avatar Tarmo avatar Alexander Zhigulich avatar Anton Grunichev avatar Valiakin Aleksei avatar Horia Coman avatar Adam Pantkowski avatar

Forkers

devindi

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.