LoggingFactory
A wrapper around the logging gem that makes instantiating logs easier. Also has a number of presets for file and standard output logging.
Installation
Add this line to your application's Gemfile:
gem 'logging_factory'
And then execute:
$ bundle
Or install it yourself as:
$ gem install logging_factory
Usage
By default all output is written to standard output. To use in your project:
public class MyClass
def initialize()
log = LoggingFactory::DEFAULT_FACTORY.log(self.class)
end
end
This will instantiate a log with the default configuration, specified by LoggingFactory::DEFAULT_LOG_CONFIGURATION:
{
output: 'STDOUT',
truncate: false,
level: :debug,
format: '[%d] %-5l [%c]: %m\n'
}
To override this configuration you can modify a log instance like this:
public class MyClass
def initialize()
log = LoggingFactory::DEFAULT_FACTORY.log(self.class, output: 'myproject.log')
end
end
Or create a new factory instant for use in your project:
MY_LOG_FACTORY = LoggingFactory.create (
output: 'myproject.log'
)
This will create an factory that will use the myproject.log for logging. Other options which are no supplied will fall back to the default unless explicitly overridden.
Examples
See spec/my_log.log for an example (run tests to generate this file).
Standard output:

Log file:
[2013-09-19 23:12:18] DEBUG [LogExample] This is a debug
[2013-09-19 23:12:18] INFO [LogExample] This is an informational
[2013-09-19 23:12:18] WARN [LogExample] This is an warning
[2013-09-19 23:12:18] ERROR [LogExample] This is an error
[2013-09-19 23:12:18] FATAL [LogExample] This is a fatal
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request