Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/janlelis/micrologger
A minimal logger based on MicroEvent.rb
https://github.com/janlelis/micrologger
logger logging microevent ruby
Last synced: 2 months ago
JSON representation
A minimal logger based on MicroEvent.rb
- Host: GitHub
- URL: https://github.com/janlelis/micrologger
- Owner: janlelis
- License: mit
- Created: 2015-03-12T21:30:14.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2022-01-01T12:04:57.000Z (almost 3 years ago)
- Last Synced: 2024-10-01T16:46:04.793Z (3 months ago)
- Topics: logger, logging, microevent, ruby
- Language: Ruby
- Homepage: https://rbjl.janlelis.com/70-get-your-microscope-for-micrologger-a-small-logger-on-top-of-microevent-rb
- Size: 7.81 KB
- Stars: 9
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: MIT-LICENSE.txt
Awesome Lists containing this project
README
# 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.