Coder Social home page Coder Social logo

hedgelog's Introduction

Hedgelog

Gem Version Build Status Dependency Status Code Climate

This gem provides an opinionated Ruby logger for writing structured JSON logs. It attempts to maintain compatibility with the standard Ruby logger api while extending it with functionality relevant to JSON logging.

Installation

Add this line to your application's Gemfile:

gem 'hedgelog'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hedgelog

Basic Usage

require 'hedgelog'

# Logging defaults to STDOUT or you can pass a file path to .new
logger = Hedgelog::Channel.new

logger.level = :info

logger.debug "Foo"
# No Output

logger.info "Foo"
=> {"message":"FOO","timestamp":"2015-07-15T12:03:08.257356","level_name":"info","level":1}

logger.info "FOO", sample: 'data'
=> {"context": {"sample":"data"},"message":"FOO","timestamp":"2015-07-15T12:05:02.302202","level_name":"info","level":1}

# It also supports logging as a block with extra data
logger.info { ["FOO", {sample: 'data'}] }
=> {"context", {"sample":"data"},"message":"FOO","timestamp":"2015-07-15T12:06:20.026807","level_name":"info","level":1}

Context

Hedgelog allows adding additional context to an instance of a logger that will get output with each log message

logger[:request_id] = 1234
=> 1234
logger.info "FOO"
=> {"request_id":1234,"message":"FOO","timestamp":"2015-07-15T12:09:33.129984","level_name":"info","level":1}

Channels

One of the primary features of Hedgelog is the usage of channels.

Channels can have their own context separate from the main loggers context. This allows including additional information for all log messages from a portion of your application.

channel = logger.channel(:database)
channel.info "FOO"
=> {"channel":"database","message":"FOO","timestamp":"2015-07-15T12:12:39.147210","level_name":"info","level":1}

# The channel does not effect the primary instance of the logger
logger.info "FOO"
=>{"message":"FOO","timestamp":"2015-07-15T12:13:31.132059","level_name":"info","level":1}

The channel instances conform to the same interface as Hedgelog. Therefore they can be passed in as standard Ruby loggers to gems that take an instance of Ruby logger for input.

DataMapper.logger = logger.channel(:database)

Scrubbing

Contributing

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

For details on the pull request process please see our contributing documentation

hedgelog's People

Contributors

jeffutter avatar daryn avatar vstehlik avatar ebmeierj avatar

Watchers

David Christensen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.