New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

null_logger

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

null_logger

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Null Logger

It's nice to be able to inject a Logger into libraries to see what's going on, but handling all that logging and providing sane defaults can be rather difficult.

If we use a Null Logger - a logger which does nothing but which supports the Logger interface - we can pass that responsibility off to those who care about logging.

Usage

In your Gemfile:

gem 'null_logger'

In your code you can use the NullLogger instance just like a real Logger:

require 'null_logger'
logger = NullLogger.instance
logger.debug "Foo"
logger.info  "Bar"
logger.warn  "Baz"
logger.error "Qux"
logger.fatal "Quux"

Of course, you'll probably want to allow people the option to pass in a logger, otherwise there's not much point, so your classes end up looking something like this:

class Groml
  attr_accessor :logger
  private :logger=, :logger

  def initialize logger = nil
    self.logger = logger || NullLogger.instance
  end

  def execute
    logger.debug "Starting execute run..."
  end
end

Authors

Craig R Webster http://barkingiguana.com/

FAQs

Package last updated on 24 Oct 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc