https://github.com/yegor256/loog
Ruby object, which you can pass to other objects, where they will use it as a logger
https://github.com/yegor256/loog
logger logging ruby ruby-gem
Last synced: 3 months ago
JSON representation
Ruby object, which you can pass to other objects, where they will use it as a logger
- Host: GitHub
- URL: https://github.com/yegor256/loog
- Owner: yegor256
- License: mit
- Created: 2019-05-04T06:14:37.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-12-24T21:08:52.000Z (4 months ago)
- Last Synced: 2025-12-26T00:31:00.631Z (4 months ago)
- Topics: logger, logging, ruby, ruby-gem
- Language: Ruby
- Homepage: https://rubygems.org/gems/loog
- Size: 301 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Object-Oriented Logger for Ruby
[](https://www.elegantobjects.org)
[](https://www.rultor.com/p/yegor256/loog)
[](https://www.jetbrains.com/ruby/)
[](https://github.com/yegor256/loog/actions/workflows/rake.yml)
[](https://badge.fury.io/rb/loog)
[](https://codeclimate.com/github/yegor256/loog/maintainability)
[](https://rubydoc.info/github/yegor256/loog/master/frames)
[](https://codecov.io/github/yegor256/loog?branch=master)
[](https://hitsofcode.com/view/github/yegor256/loog)
Loog is an object-oriented logging wrapper around Ruby
[`Logger`](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger.html).
First, install it:
```bash
gem install loog
```
Then, use it like this:
```ruby
require 'loog'
Loog::VERBOSE.info('Hello, world!')
```
The gem is basically a provider of a few pre-configured loggers, which
you can use for production (`Loog::REGULAR`) or for testing (`Loog::VERBOSE`).
You can also shut it up with `Loog::NULL`.
There is also `Loog::Buffer` class that you can use for testing.
It accumulates all log calls and then returns the entire output
through the `to_s()` method.
Also, you can "tee" two loogs, with the help of `Loog::Tee`. For example,
to record everything in a buffer and also show in the console:
```ruby
require 'loog'
require 'loog/tee'
buf = Loog::Buffer.new
loog = Loog::Tee.new(Loog::VERBOSE, buf)
loog.info('Hello, world!')
assert(buf.to_s.include?('Hello'))
```
You can also truncate long messages with `Loog::Ellipsized`:
```ruby
require 'loog'
require 'loog/ellipsized'
loog = Loog::Ellipsized.new(Loog::VERBOSE, 20)
loog.info('This is a very long message that will be truncated')
# prints: "This is...truncated"
```
You can add ANSI colors to log messages with `Loog::Colorful`,
which prints debug messages in dark gray, warnings in orange,
and errors in red:
```ruby
require 'loog'
require 'loog/colorful'
loog = Loog::Colorful.new(Loog::VERBOSE)
loog.debug('This is dark gray')
loog.warn('This is orange')
loog.error('This is red')
```
## How to contribute
Read
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
Make sure your build is green before you contribute
your pull request. You will need to have
[Ruby](https://www.ruby-lang.org/en/) 2.3+ and
[Bundler](https://bundler.io/) installed. Then:
```bash
bundle update
bundle exec rake
```
If it's clean and you don't see any error messages, submit your pull request.