Skip to content

Commit

Permalink
Merge pull request #22 from mrnugget/api_readme
Browse files Browse the repository at this point in the history
Add basic API usage information to README
  • Loading branch information
Lennart Koopmann committed Apr 15, 2014
2 parents 2f5d3c3 + 25d4d3e commit e32a53d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.rdoc
Expand Up @@ -6,6 +6,39 @@ Works with Ruby 1.8.7, 1.9.x. and 2.0.x.

{<img src="https://travis-ci.org/Graylog2/gelf-rb.png?branch=master" alt="Build Status" />}[https://travis-ci.org/Graylog2/gelf-rb]

== Usage
=== Gelf::Notifier

This allows you to sent arbitary messages via UDP to your Graylog2 server.

n = GELF::Notifier.new("localhost", 12201)

# Send with custom attributes and an additional parameter "foo"
n.notify!(:short_message => "foo", :full_message => "something here\n\nbacktrace?!", :_foo => "bar")

# Pass any object that responds to .to_hash
n.notify!(Exception.new)

=== Gelf::Logger

The Gelf::Logger is compatible with the standard Ruby Logger interface and can be used interchangeably.
Under the hood it uses Gelf::Notifier to send log messages via UDP to Graylog2.

logger = GELF::Logger.new("localhost", 12201, "WAN", { :facility => "appname" })

logger.debug "foobar"
logger.info "foobar"
logger.warn "foobar"
logger.error "foobar"
logger.fatal "foobar"

logger << "foobar"

Since it's compatible with the Logger interface, you can also use it in your Rails application:

# config/environments/production.rb
config.logger = GELF::Logger.new("localhost", 12201, "WAN", { :facility => "appname" })

== Note on Patches/Pull Requests

* Fork the project.
Expand Down

0 comments on commit e32a53d

Please sign in to comment.