Giter Site home page Giter Site logo

bunyan's Introduction

Bunyan

Bunyan is a thin ruby wrapper around a MongoDB capped collection, created with high-performance, flexible logging in mind.

Bunyan is not intended to be used as a drop-in replacement for the default rails logger. If you need to do this, please see peburrows' mongo_db_logger.

However, there is planned support for a flexible middleware component to drop in to your rails app.

Install

gem install bunyan

Configure

The only configuration options required are the database and collection name.

For rails apps, put the following config block in an initializer.

# config/initializers/bunyan.rb
Bunyan::Logger.configure do
  # required options
  database   'bunyan_logger'
  collection 'development_log'

  # optional
  host     'some.remote.host' # defaults to localhost
  port     '12345'            # defaults to 27017
  disabled true

  # other connection option
  # Specify a valid ruby driver connection object (single / pair)
  # if you do so, host / port are ignored 
  connection = $connection
end

# Gemfile
gem 'bson_ext', '1.1' # set the version to whatever the current version of bson the mongo gem is using

Usage

You can access the bunyan logger anywhere is your app via Bunyan::Logger. The Logger class is implemented as a singleton, and you can call any instance method on the Logger class. This is implemented with some method_missing magic, which is explained in a bit more detail below.

Middleware

To make use of Bunyan in your web apps, you need some way to capture request data. I have added an example middleware (which is extremely, extremely ugly) which you can find at examples/middleware.rb.

There are plans for a standard middleware API, but it has not yet been implemented. If you have interest in helping/collaborating on this feature, please get in touch with me.

Until the middleware API is complete, please use this example middleware at your own risk!

Internals

Bunyan makes heavy usage of method_missing both at the class and instance level. At the class level, this is purely for convenience to pass missing class methods to the singleton instance, which precludes us from needing to use Logger.instance directly. At the instance level, method_missing is used to provide a very thin layer around MongoDB, via the Mongo driver.

The net effect of this is that there is no reason to muck around with calling methods directly on Bunyan::Logger.instance, because all methods that don't already exist at the class level will be sent to Bunyan::Logger.instance.

Bunyan::Logger.count == Bunyan::Logger.instance.count # => true

Also, you can call any instance methods Bunyan::Logger that you would otherwise call on a Mongo collection object.

More

TODO

  • Ability to specify auth creds for making a mongo connection
  • Fail silently if no mongo server running
  • Ability to limit bunyan to only run in certain environments
  • Add middleware client for easy drop-in to rails/rack apps
  • Add ability to connect to a remote mongo server
  • Ability to configure size of capped collection

bunyan's People

Contributors

ajsharp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bunyan's Issues

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.