0.0
No commit activity in last 3 years
No release in over 3 years
Writes log to db and log files (configurable destinations) according the context and exposes the log entries via http
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

context_logger

Setup

In your Gemfile add:

gem 'context_logger'

Setting destinations

In your config file (e.g. config/environment.rb) add

ContextLogger.set_destinations(:all)

To configure logging distination replace :all with any subset of:

{
write_rails_log: true,
write_context_log: true,
write_db_log: true
}

e.g. if you want to exclude logging to DB:

ContextLogger.set_destinations({
write_rails_log: true,
write_context_log: true
})

Setting up the options (default values)

Instead of passing the values that don't change often (e.g. server, ), it's possible to set them using setup method:

ContextLogger.setup({context: :publish, action_id: 1, server: 'myserver.com'})

It's possible to overid them anytime. To see current value of options, just call:

ContextLogger.options

Logging

ContextLogger exposes the following methods for logging: :info, :warn, :error, :debug, :fatal And here are the params (with defaults):

message, method, params, stack_trace=nil, action_id=nil, context=nil ,server=nil

An example of logging a warning message:

ContextLogger.warn('Just another message', :store_data, {data:{a:1, b:2}}, "'Range.detach' is now a no-op, as per DOM (http://dom.spec.whatwg.org/#dom-range-detach).", 1)

HTTP API:

In order to write the log also to db_log, you should set it using set_destination method:

ContextLogger.set_destinations({
...
write_db_log: true,
...
})

The log entries from the DB are available via HTTP API:

http://server_name/api/v1/resources/context_loggers?action_id=xxx