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

hatchet

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hatchet

  • 0.2.14
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Hatchet

Ruby logging library that provides the ability to add class/module specific filters.

This README provides a brief overview of Hatchet, see the main site for more complete documentation and tutorials.

Build Status
Code Climate

Installation

Add this line to your application's Gemfile:

gem 'hatchet'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hatchet

Usage

Logging

To use the logger you must add it to your classes as a mixin or use it to extend your modules. Then you can call the logger through the methods log and logger. They are aliases for the same method to ease migration.

Classes
class Foo
  include Hatchet

  def self.class_work
    log.info { 'Doing some class work' }
  end

  def work
    log.info { 'Doing some work' }
  end

  def dangerous_work
    log.info { 'Attempting dangerous work' }
    attempt_dangerous_work
    log.info { 'Dangerous work complete' }
    true
  rescue => e
    log.error "Dangerous work failed - #{e.message}", e
    false
  end
end
Modules
module Bar
  include Hatchet

  def self.work
    log.info { 'Doing some module work' }
  end

  def work
    log.info { 'Doing some mixin work' }
  end
end

Configuration

Standard
Hatchet.configure do |config|
  # Set the level to use unless overridden (defaults to :info)
  config.level :info
  # Set the level for a specific class/module and its children
  config.level :debug, 'Namespace::Something::Nested'

  # Add as many appenders as you like
  config.appenders << Hatchet::LoggerAppender.new do |appender|
    # Set the logger that this is wrapping (required)
    appender.logger = Logger.new('log/test.log')
  end
end
Sinatra

Use the standard configuration method but also register Hatchet as a helper where appropriate:

register Hatchet

Note that you may have to use the log alias as Sinatra already has a logger method.

Rails

Hatchet includes a Railtie that is loaded automatically and wraps the Rails.logger. The Hatchet configuration object is available through config.hatchet within your standard configuration files for fine-tuning your Hatchet configuration.

To make it so your log calls are scoped to your controllers you also need to add Hatchet to your ApplicationController:

class ApplicationController < ActionController::Base
  include Hatchet
end

You could include it in your models so that each of those has its own logging context too.

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

All pull requests should come complete with tests when appropriate and should follow the existing style which is best described in Github's Ruby style guide.

FAQs

Package last updated on 24 Oct 2019

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