Skip to content

svrana/sinatra-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A simple file logger for use in Sinatra

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages