Plogger
Introduction
Plogger stands for Papinotas Logger or Phoenix Logger (our current project, which raised the need for this gem). Plogger is a simple logging gem which receives a little more information than Rails.Logger
. Plogger outputs the log in a parser friendly format, ready for other software such as Logstash to process it.
Instalation
Add gem 'plogger'
to your gemfile.
Configuring
# environments/[Environment].rb
Rails.application.configure do
Plogger.configure do |config|
config.logger = ActiveSupport::Logger.new(STDOUT) # Or whatever logger you want to configure
config.module = 'MainModule' # Optional
end
end
Usage
The usage is similar to how you use the Rails Logger, but you can also log exceptions.
begin
1/0
rescue e
trace = Plogger.exception(e, category: 'Bundle Creation')
# => trace = "130AH93MWS2"
return render "Too bad, an exception was raised. Read the full error at #{trace}"
end
trace_2 = Plogger.info("Processing ready", category: 'Bundle Creation')
render "Your process finished successfully, check the logs at #{trace_2}"
Plogger has the following methods: exception
, error
, warning
, info
, debug
. It will use the logger you supplied in the config to output them, so make sure you have enabled the log level you are trying to use.
Params
Each of these methods can receive the following keyword params:
Param | Explanation | Default |
---|---|---|
category | Use it to categorize the thing you are logging, so you can later group related logs in Kibana or something | '' |
type | Use it to manifest if the current log is generated by a system action or a user action | 'system' |
user_id | Use it to track the user that is generating the log | '' |
account_id | In Phoenix we use accounts (a user can have many accounts). You can track that too | '' |
extra_info | A hash with additional tags you can print in the log | {} |
Example call:
Plogger.info("Processing ready", type: 'user', category: "Bundle Creation", user_id: 1, extra_info: {happy: "yes"})
# Will output 'Processing ready -- trace=194fjx43gp type='user' category='Bundle Creation' user_id=1 happy='yes'