Sha256: ab41b5efe48d4681e9105d6306372e0757e1d81a63b2aa7c5416948007084426

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# MicroLogger [![[version]](https://badge.fury.io/rb/microevent.svg)](https://badge.fury.io/rb/microevent)  [![[CI]](https://github.com/janlelis/micrologger/workflows/Test/badge.svg)](https://github.com/janlelis/micrologger/actions?query=workflow%3ATest)

A minimal logger based on [MicroEvent](https://github.com/janlelis/microevent.rb).

## Setup

Add to your `Gemfile`

```ruby
gem 'micrologger'
```

## How to Use It

A new logger has to be configured what should be done on log events using handler procs. There are two default handlers for logging to STDOUT/STDERR included:

```ruby
$logger = MicroLogger.new
$logger.register :info, :stdout
$logger.register :fatal, :stderr

$logger.log "debug" # STDOUT: debug
$logger.log "error", :fatal # STDERR: error
```

For any andvanced or customized behaviour, you will need to register your own blocks/procs:


### Example: Log to File

```ruby
$logger = MicroLogger.new
$logger.register :warn, :stderr
$logger.register :warn do |message, meta|
  File.open("logfile.#{meta[:level]}.txt", "a"){ |f| f.puts "#{meta[:time]} | #{message}" }
end

$logger.log "hey", :warn # Will write to STDERR and logfile.warn.txt
```

Other ideas you could do: Send data to a remote endpoint, send emails, send to analytics...


## J-_-L

Copyright (c) 2015 [Jan Lelis](https://janlelis.com). See MIT-LICENSE for details.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
micrologger-0.1.3 README.md