Skip to content

Instantly share code, notes, and snippets.

@aussielunix
Last active December 27, 2015 03:39
Show Gist options
  • Save aussielunix/7261549 to your computer and use it in GitHub Desktop.
Save aussielunix/7261549 to your computer and use it in GitHub Desktop.
configurable logging using the yell rubygem.

ruby logging

  • Global logger with yell config that is read in from a yaml file.
  • This allows end users to configure logging to their own needs.
  • new adapters etc can be add including a GELF adapter.
  • yell will read and honour RAILS_ENV, RACK_ENV or YELL_ENV and defaults to development

Goals

As a developer I would love to have at my disposal, via the way of a mixin, an easy way to log things without having to understand how. I should be able to just simply state what I want to log and at what level.

debug('debug message')
info('this happened')

As an end user I should be able to chose what level of logging is displayed to the screen.

--verbose=WARN
--verbose=DEBUG

Using yell as outlaid in this gist gives the mixin and the helper methods to achieve this however there is still no way to control what is sent to STDOUT/console.

This needs more experimentation/thought

#!/usr/bin/env ruby
require 'yell'
@logger = Yell.load!('config/yell.yml')
def debug(progname = nil, &block); @logger.debug(progname,&block); end
def info(progname = nil, &block); @logger.info(progname,&block); end
def warn(progname = nil, &block); @logger.warn(progname,&block); end
def error(progname = nil, &block); @logger.error(progname,&block); end
def fatal(progname = nil, &block); @logger.fatal(progname,&block); end
debug('debug message')
info('info message')
warn('warn message')
error('error message')
fatal('fatal messge')
production:
:level: 'gte.info'
:adapters:
- :file:
:level: 'lte.warn'
:filename: 'log/production.log'
- :file:
:level: 'gte.error'
:filename: 'log/error.log'
development:
:level: 'gte.info'
:adapters:
- :stdout:
:colors: true
:level: 'lte.warn'
- :stderr:
:colors: true
:level: 'gte.error'
- :file:
:filename: 'log/development.log'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment