GithubHelp home page GithubHelp logo

cossio / miniloggers.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from julialogging/miniloggers.jl

0.0 1.0 0.0 547 KB

Julia logger with customizable logging string

License: MIT License

Julia 100.00%

miniloggers.jl's Introduction

MiniLoggers.jl

Documentation Build Status JuliaHub
StableDev BuildCoverage pkgevalversion

MiniLoggers.jl provides Julia logger with minimal setup and simple yet powerful format of logging strings. It allows to build custom and compact logging, which supports coloring, output to external files, timestamps and many more.

Installation

MiniLoggers.jl is a part of General registry, so it should be installed with

julia> using Pkg; Pkg.add("MiniLoggers")

Examples of usage

In it's most simple form, MiniLoggers.jl is used as

using MiniLoggers

MiniLogger(minlevel = MiniLoggers.Debug) |> global_logger

x = 1
y = "asd"

@debug "Values: " x y
@info "Values: " x y
@warn "Values: " x y
@error "Values: " x y

and produces

default_fmt

But one can make it more colourful and add more details with initilization like the following

MiniLogger(minlevel = MiniLoggers.Debug, 
           format = "{[{timestamp}] - {level} - :func}{{module}@{basename}:{line:cyan}:light_green}: {message}") |> global_logger

@debug "Values: " x y
@info "Values: " x y
@warn "Values: " x y
@error "Values: " x y

which yields

colour1_fmt

Or, we can add small unicode magic and get fancy two-line logging format

MiniLogger(minlevel = MiniLoggers.Debug, 
           format = "╭{[{timestamp}] - {level} - :func}{{module}@{basename}:{line:cyan}:light_green}\n╰→ {message}") |> global_logger

colour3_fmt

Format constructor is very flexible, so the output of log messages is mostly limited by your imagination.

At the same time, you can go other way arround and remove all extra details completely turning it effectively to a basic println command, thus making it convinient to plug minilogger in packages like LoggingExtras.jl

MiniLogger(minlevel = MiniLoggers.Debug, format = "{message}") |> global_logger

minimal_fmt

Also MiniLoggers.jl support Julia exceptions, so you can generate error messages in a usual way

MiniLogger(minlevel = MiniLoggers.Debug, 
           format = "{[{timestamp}] {level}:func} {module}@{basename}:{line:cyan}: {message}") |> global_logger

try
    error("Some error")
catch err
    @error (err, catch_backtrace())
end

error_fmt

miniloggers.jl's People

Contributors

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