Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Make compatible with Heroku by adding logs to both Mongo and STDOUT #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Log to a central MongoDB from Rails apps.

include CentralLogger::Filter

1. For use with Heroku you need to prevent the rails_log_stdout plugin from being added by Heroku:

mkdir vendor/plugins/rails_log_stdout
touch vendor/plugins/rails_log_stdout/.gitkeep

1. If using Rails 3, SKIP this step. Otherwise, add the following to config/environment.rb:

require 'central_logger'
Expand Down
4 changes: 3 additions & 1 deletion lib/central_logger/mongo_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def add_metadata(options={})
end

def add(severity, message = nil, progname = nil, &block)
$stdout.puts message
if @level <= severity && message.present? && @mongo_record.present?
# do not modify the original message used by the buffered logger
msg = logging_colorized? ? message.gsub(/(\e(\[([\d;]*[mz]?))?)?/, '').strip : message
Expand Down Expand Up @@ -133,7 +134,8 @@ def resolve_config
def connect
@mongo_connection ||= Mongo::Connection.new(@db_configuration['host'],
@db_configuration['port'],
:auto_reconnect => true).db(@db_configuration['database'])
:auto_reconnect => true,
:timeout => 5).db(@db_configuration['database'])

if @db_configuration['username'] && @db_configuration['password']
# the driver stores credentials in case reconnection is required
Expand Down