Ruby SDK
Install the Logdash Ruby SDK, send your first log and your first metric.
Install the package, paste your API key and the first log lands in the dashboard within a second. Everything below is copied from the Ruby SDK README.
Install
gem install logdash Initialise
Create a project in Logdash, copy its API key and keep it in an environment variable. The key identifies the project the data lands in.
require 'logdash'
logdash_client = Logdash.create(api_key: ENV['LOGDASH_API_KEY'])
logger = logdash_client[:logger]
metrics = logdash_client[:metrics] Send a log
logger.info('Application started successfully')
logger.error('An unexpected error occurred')
logger.warn('Low disk space warning') Send a metric
Metrics are named numbers. Set one to an absolute value or mutate it by a delta, and Logdash charts the history.
metrics.set('users', 0)
metrics.mutate('users', 1) Works with
- Ruby on Rails
- Sinatra
- Rack
- Sidekiq
FAQ
How do I wire it into Rails?
Create `config/initializers/logdash.rb`, call `Logdash.create` inside `ActiveSupport.on_load(:after_initialize)` and assign `$logger` and `$metrics` so they are available app-wide.
What does Logdash.create return?
A hash. Read `client[:logger]` for logging and `client[:metrics]` for counters and gauges.
Which log levels does the logger expose?
`info`, `error`, `warn`, `debug`, `verbose`, `http` and `silly`.