0.0
No commit activity in last 3 years
No release in over 3 years
A logger for Sinatra applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
~> 2.0

Runtime

>= 0
 Project Readme

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.