Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brandymint/auto_logger
Mixin to use automatically configured `logger`
https://github.com/brandymint/auto_logger
autologger gem ruby ruby-gem
Last synced: about 2 months ago
JSON representation
Mixin to use automatically configured `logger`
- Host: GitHub
- URL: https://github.com/brandymint/auto_logger
- Owner: BrandyMint
- License: mit
- Created: 2018-09-03T16:52:52.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-21T02:31:35.000Z (almost 2 years ago)
- Last Synced: 2024-10-05T07:14:10.007Z (3 months ago)
- Topics: autologger, gem, ruby, ruby-gem
- Language: Ruby
- Size: 22.5 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# AutoLogger
[![Build Status](https://travis-ci.org/BrandyMint/auto_logger.svg)](https://travis-ci.org/BrandyMint/auto_logger)
Упрощяет подключение уникальных логгеров для модулей и классов. После
подключения в модуль или класс через `include AutoLogger` добавляет метод
`logger` который пишет логи в файл автоматически сформированные из измени
модуля/класса в каталог `./log`## Installation
Add this line to your application's Gemfile:
```ruby
gem 'auto_logger'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install auto_logger
## Usage
### Instance usage
```
class SomeService
include AutoLoggerdef perform
logger.info 'some' # writes info into ./logs/some_service.log
end
end
```### Grape example
Иногда необходимо насильно указать имя файла для лога. Например при подключении
в модули/класс без имени, в частности в grape-контролерах:```
class PublicAPI::OrdersAPI < Grape::API
helpers do
include AutoLogger::Named.new(name: :orders_api)
end
end
```## Usage in module context
```
module Custom
extend AutoLoggerdef self.perform
logger.info "Do..."
end
endCustom.logger.info "Do.."
```## Setup custom logger
```
AutoLogger.logger_builder = -> (tag, default_formatter) {
ActiveSupport::TaggedLogging
.new(LogStashLogger.new(type: :stdout))
.tagged(tag)
}
```## Collapse all logs to one (useful for development)
```
if ENV['COLLAPSE_AUTO_LOGGER'].present?
if ENV['COLLAPSE_AUTO_LOGGER'] == 'STDOUT'
logger = Logger.new(STDOUT)
else
logger = Rails.logger
end
AutoLogger.logger_builder = -> (tag, default_formatter) {
ActiveSupport::TaggedLogging
.new(logger)
.tagged(tag)
}
end
```## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/dapi/auto_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the AutoLogger project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/dapi/auto_logger/blob/master/CODE_OF_CONDUCT.md).