1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
# MonoLogger
Ruby's stdlib Logger wraps all IO in mutexes. Ruby 2.0 doesn't allow you to
request a lock in a trap handler because that could deadlock. This gem fixes
this issue by giving you a lock-free logger class.
If you've ever seen `log writing failed. can't be called from trap context`,
you're in the right place!
## Installation
Add this line to your application's Gemfile:
gem 'mono_logger'
And then execute:
$ bundle
Or install it yourself as:
$ gem install mono_logger
## Usage
It's simple, just use `MonoLogger` anywhere you'd use `Logger`:
```ruby
require 'logger'
logger = Logger.new(STDOUT)
logger.level = Logger::WARN
logger.debug("Created logger")
logger.info("Program started")
logger.warn("Nothing to do!")
```
Turns into
```ruby
require 'mono_logger'
logger = MonoLogger.new(STDOUT)
logger.level = MonoLogger::WARN
logger.debug("Created logger")
logger.info("Program started")
logger.warn("Nothing to do!")
```
That's it! No more errors!
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request
## License
MIT. See LICENSE.txt for more details.
|