Giter VIP home page Giter VIP logo

sinatra-log's Introduction

Sinatra::Log Build Status

A simple file logger written for use by Sinatra apps.

Installation

Add this line to your application's Gemfile:

gem 'sinatra-log'

And then execute:

$ bundle install

Or install it globally:

$ gem install sinatra-log

Usage

require 'sinatra/log'

class MyProject
  def self.log
    @logger ||= Sinatra::Log.new(:logger_name => 'myproject',
                                 :log_filename => '/var/log/development.log',
                                 :loglevel => 'WARN',
                                 :enabled => true,
                                 :project_dir => '/var/opt/myproj')
  end
end

MyProject.log.error "Error level log" 	# You will see this
MyProject.log.warn "Warning level log"  # You will see this
MyProject.log.info "Info level log"     # But not this
MyProject.log.debug "Debug level log"   # or this

This will configure the logger to output messages at WARN level or higher to be directed to the file /var/log/development.log. Logging is enabled and the log4r logger is named 'myproject'.

Each log messages that is generated by log4r will contain the full path and filename of the origin of the log message. Specifying the project root directory in :project_dir, will cause that directory to be removed from each log message.

History

I wrote this wrapper around log4r in 2014 for a small Sinatra project at Lookout. As the project ended, the code was pulled out and open sourced by ismith and included in lookout-rack-utils.

Changes

The changes here remove the Lookout specific bits of the logging - the use of specific configatron values that may not match your project or style. Graphite logging was also thrown out, though that could be re-added if desired. And of course there was a namespace change.

sinatra-log's People

Watchers

 avatar  avatar  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.