https://github.com/prodis/rails-labeled_log
A tool to use Rails Tagged Logging easily in your Ruby classes.
https://github.com/prodis/rails-labeled_log
Last synced: 22 days ago
JSON representation
A tool to use Rails Tagged Logging easily in your Ruby classes.
- Host: GitHub
- URL: https://github.com/prodis/rails-labeled_log
- Owner: prodis
- License: mit
- Created: 2015-09-18T22:42:05.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-09-28T22:08:44.000Z (almost 11 years ago)
- Last Synced: 2025-10-04T01:59:53.972Z (10 months ago)
- Language: Ruby
- Homepage:
- Size: 199 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Rails Labeled Log
A tool to use Rails Tagged Logging easily in your Ruby classes.
[](http://badge.fury.io/rb/rails-labeled_log)
[](https://travis-ci.org/prodis/rails-labeled_log)
[](https://coveralls.io/github/prodis/rails-labeled_log?branch=master)
[](https://codeclimate.com/github/prodis/rails-labeled_log)
[](https://gemnasium.com/prodis/rails-labeled_log)
## Installing
### Gemfile
```ruby
gem 'rails-labeled_log'
```
### Direct installation
```console
$ gem install rails-labeled_log
```
## Using
### Rails::LabeledLog::Logging module
```ruby
require 'rails-labeled_log'
# Include Rails::LabeledLog::Logging module in your class
module FakeModule
class FakeClass
include Rails::LabeledLog::Logging
def do_something
# Log some info here
log_info 'I did something'
end
end
end
fake = FakeModule::FakeClass.new
fake.do_something
# You also can use class methods
FakeModule::FakeClass.log_error 'Something was wrong'
# Optionally, you can supply additional labels for all log methods
FakeModule::FakeClass.log_warn 'Pay attention!', 'Warning'
```
Rails log will be labeled with the class name (and optinal additional labels):
```
[FakeModule::FakeClass] I did something at 2015-09-21 00:33:17 -0300
[FakeModule::FakeClass] Something was wrong at 2015-09-21 00:33:18 -0300
[FakeModule::FakeClass] [Warning] Pay attention! at 2015-09-21 00:33:19 -0300
```
##### Available (private) instance methods and class methods
- log_info
- log_error
- log_warn
- log_debug
- log_fatal
### Rails::LabeledLog::Logger class
```ruby
require 'rails-labeled_log'
logger = Rails::LabeledLog::Logger.new('One', 'Two')
logger.info 'My info message'
logger.info 'My info message', 'Three', 'Four'
```
In the Rails Log:
```
[One] [Two] My info message at 2015-09-21 01:01:43 -0300
[One] [Two] [Three] [Four] My info message at 2015-09-21 01:01:44 -0300
```
##### Available methods
- info
- error
- warn
- debug
- fatal
## Author
[Fernando Hamasaki de Amorim (prodis)](http://prodis.blog.br)

## Contributing to Rails Labeled Log
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
- Fork the project.
- Start a feature/bugfix branch.
- Commit and push until you are happy with your contribution.
- Don't forget to rebase with branch master in main project before submit the pull request.
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.