Project

singlogger

0.0
No commit activity in last 3 years
No release in over 3 years
A simple Singleton wrapper around the ruby Logger class, gem-ified it because I found myself using it in several different projects
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 10.0
~> 0.14.1
~> 3.2
 Project Readme

SingLogger

This is a simple singleton wrapper around the Logger class.

I'm sure others have done this, but I found myself copying and pasting this wrapper into every project I write, so I thought it made sense to put it into a single gem that I can import wherever I want!

Installation

Add this line to your application's Gemfile:

gem 'singlogger'

And then execute:

$ bundle

Or install it yourself as:

$ gem install singlogger

Usage

I generally start by using SingLogger.set_level_from_string() when the application runs, based on a user parameter. You can use SingLogger.set_level_from_string() or SingLogger.set_level() any time you want to change it. set_level() takes logger constants, such as ::Logger::DEBUG, ::Logger::INFO, etc.

If you don't want to use STDERR for the sink, it's important to set the sink: parameter of SingLogger.instance() the first time you use it. That'll set the sink of the logger going forward.

To actually log, in the initialize() function of your classes, add

@logger = SingLogger.instance()

Then when you want to log:

@logger.debug("debug message")
@logger.info("info message")
@logger.warn("warn message")
@logger.error("error message")
@logger.fatal("fatal message")

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/iagox86/singlogger.