Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f277cd3
Merge branch 'release/1.3.1'
AlekSi Oct 28, 2011
5abd982
Merge branch 'develop'
AlekSi Oct 28, 2011
7c1ff75
Merge branch 'develop'
AlekSi Nov 3, 2011
2379373
Merge branch 'release/v1.3.2'
AlekSi Dec 2, 2011
abdc8c6
Add rails log tag support.
mitnal May 25, 2012
6042848
Fix wrong method call.
mitnal May 25, 2012
ccd7144
Add documentation and tests.
mitnal May 25, 2012
aead6b2
Added formatter field to Logger
mollstam Sep 13, 2012
320dd3f
added test for check formatter attribute
mollstam Sep 13, 2012
69895fa
Merge pull request #10 from mollstam/master
Sep 13, 2012
e1237c0
clean up rakefile
Jan 26, 2013
8c4b5bc
support pure hashes as message in logger
Jan 26, 2013
215ef2f
Regenerate gemspec for version 1.4.0
Jan 26, 2013
e8ef4fb
Add more rubies to Travis-CI config
AlekSi Sep 2, 2013
9e986d6
Merge pull request #14 from AlekSi/patch-1
Sep 2, 2013
460977e
fixes chunking for subclasses of GELF::Notifier
Sep 4, 2013
19d1d87
uses smaller data for chunking test
Sep 4, 2013
69cdd1e
lmao if you had no gemfile in 2013
Sep 4, 2013
55aedaa
downgrade shoulda
Sep 4, 2013
478be2a
Merge pull request #15 from barooo/master
Sep 4, 2013
38e85a6
fix #rubby 2.0 tests
Sep 5, 2013
5f94664
debugging for travis-ci
Sep 5, 2013
69a0372
ruby 1.8.7 compat #13
Sep 5, 2013
467ce5f
added travis-ci build status, updated copyright years and supported r…
Sep 5, 2013
ef2d28e
use default facility if progname is blank
slawosz Oct 8, 2013
1b0bcfe
Merge pull request #16 from centralway/master
Oct 9, 2013
429ac9b
fix breaking test. ruby 1.8.7 compat for #16
Oct 9, 2013
2f5d3c3
contributing guidelines
Apr 15, 2014
25d4d3e
Add basic API usage information to README
mrnugget Apr 15, 2014
e32a53d
Merge pull request #22 from mrnugget/api_readme
Apr 15, 2014
e93e350
don't run on all those rubbies
Apr 15, 2014
6170d62
Merge and fix
meltingice Apr 21, 2014
a594b61
Add formatter support
meltingice Apr 21, 2014
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ rvm:
- ree
- 1.9.2
- 1.9.3
<<<<<<< HEAD
- jruby-18mode
- jruby-19mode
- rbx-18mode
# - rbx-19mode
=======
- 2.0.0
- jruby-19mode
>>>>>>> master

notifications:
irc: "irc.freenode.org#graylog2"
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Thank you very much for considering contributing to the Graylog2 project! We <3 our community.

To make handling all the community contributions as easy as possible for us we ask you to follow these steps as good as possible:

## Bug reports

1. Please sign the [TORCH Contributor Agreement](https://github.com/Graylog2/graylog2-web-interface/raw/0.20/ContributorAgreement.pdf) if your issue contains
any code. We cannot go on without this.
2. Search the issues of both the [graylog2-server](https://github.com/Graylog2/graylog2-server) and [graylog2-web-interface](https://github.com/Graylog2/graylog2-web-interface)
repositories for opened or closed issues to avoid duplicating effort.
3. Be clear about the issue. It is always better to include too much information than too little. Include screenshots explaining the problem if you can.
4. Always include the versions of affected Graylog2 components you are running.
5. Provide exact steps to reproduce the issue if at any possible.

## Pull requests

1. Please sign the [TORCH Contributor Agreement](https://github.com/Graylog2/graylog2-web-interface/raw/0.20/ContributorAgreement.pdf) before sending pull requests.
We cannot accept code without this.
2. Search the issues of both the [graylog2-server](https://github.com/Graylog2/graylog2-server) and [graylog2-web-interface](https://github.com/Graylog2/graylog2-web-interface)
repositories for opened or closed issues to avoid duplicating effort.
3. Contact the [TORCH](http://www.torch.sh/) team via [any communication channel](http://graylog2.org/support) (contact form, mailing list, IRC, Github issue tracker) before working on a big change to make sure
that there are chances of acceptance.
4. Include tests if at any possible.
5. Submit the pull request.

## Feature requests

We are always happy about any feature request! Do not hesitate to create as many feature request issues as you want.

1. Please sign the [TORCH Contributor Agreement](https://github.com/Graylog2/graylog2-web-interface/raw/0.20/ContributorAgreement.pdf) if your issue contains
any code. We cannot go on without this.
2. Search the issues of both the [graylog2-server](https://github.com/Graylog2/graylog2-server) and [graylog2-web-interface](https://github.com/Graylog2/graylog2-web-interface)
repositories for opened or closed issues to avoid duplicating effort.
3. Explain exactly what feature you'd like to see and always include a use case for why you think it is useful.
14 changes: 4 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
source "http://rubygems.org"
source "https://rubygems.org"

gem "json"

group :development do
gem "bundler"
gem "jeweler"
gem "shoulda"
gem "mocha"
gem "rdoc"
end
gem "shoulda", "~> 2.11.3"
gem "jeweler", "~> 1.8.7"
gem "mocha", "~> 0.14.0"
59 changes: 41 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,55 @@
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
git (1.2.5)
jeweler (1.8.3)
addressable (2.3.5)
builder (3.2.2)
faraday (0.8.9)
multipart-post (~> 1.2.0)
git (1.2.6)
github_api (0.10.1)
addressable
faraday (~> 0.8.1)
hashie (>= 1.2)
multi_json (~> 1.4)
nokogiri (~> 1.5.2)
oauth2
hashie (2.1.0)
highline (1.6.21)
jeweler (1.8.7)
builder
bundler (~> 1.0)
git (>= 1.2.5)
github_api (= 0.10.1)
highline (>= 1.6.15)
nokogiri (= 1.5.10)
rake
rdoc
json (1.7.0)
json (1.8.1)
jwt (0.1.11)
multi_json (>= 1.5)
metaclass (0.0.1)
mocha (0.11.3)
mocha (0.14.0)
metaclass (~> 0.0.1)
rake (0.9.2.2)
rdoc (3.12)
multi_json (1.9.2)
multi_xml (0.5.5)
multipart-post (1.2.0)
nokogiri (1.5.10)
oauth2 (0.9.3)
faraday (>= 0.8, < 0.10)
jwt (~> 0.1.8)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
rack (1.5.2)
rake (10.2.2)
rdoc (4.0.1)
json (~> 1.4)
shoulda (3.0.1)
shoulda-context (~> 1.0.0)
shoulda-matchers (~> 1.0.0)
shoulda-context (1.0.0)
shoulda-matchers (1.0.0)
shoulda (2.11.3)

PLATFORMS
ruby

DEPENDENCIES
bundler
jeweler
json
mocha
rdoc
shoulda
jeweler (~> 1.8.7)
mocha (~> 0.14.0)
shoulda (~> 2.11.3)
37 changes: 36 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,45 @@ This is the new GELF gem written by Alexey Palazhchenko. It is based on the old

Works with Ruby 1.8.7, 1.9.x and JRuby. 1.8.6 is not supported.

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

== Installation

gem install gelf

== 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 All @@ -19,4 +54,4 @@ Works with Ruby 1.8.7, 1.9.x and JRuby. 1.8.6 is not supported.

== Copyright

Copyright (c) 2010-2011 Lennart Koopmann and Alexey Palazhchenko. See LICENSE for details.
Copyright (c) 2010-2013 Lennart Koopmann and Alexey Palazhchenko. See LICENSE for details.
27 changes: 16 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end

task :default => :test

begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
Expand All @@ -42,16 +44,19 @@ begin
test.rcov_opts << '--exclude gem'
test.verbose = true
end
rescue LoadError
# nothing
rescue LoadError => e
task :rcov do
puts e
abort "rcov is not available. Run: gem install rcov"
end
end

require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "gelf #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
#require 'rake/rdoctask'
#Rake::RDocTask.new do |rdoc|
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
#
# rdoc.rdoc_dir = 'rdoc'
# rdoc.title = "gelf #{version}"
# rdoc.rdoc_files.include('README*')
# rdoc.rdoc_files.include('lib/**/*.rb')
#end
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.0.beta1
1.4.0.beta2
4 changes: 2 additions & 2 deletions gelf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = "gelf"
s.version = "1.4.0.beta1"
s.version = "1.4.0.beta2"

s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Alexey Palazhchenko", "Lennart Koopmann"]
s.date = "2012-05-03"
s.date = "2014-04-21"
s.description = "Library to send GELF messages to Graylog2 logging server. Supports plain-text, GELF messages and exceptions."
s.email = "[email protected]"
s.extra_rdoc_files = [
Expand Down
57 changes: 55 additions & 2 deletions lib/gelf/logger.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module GELF
# Methods for compatibility with Ruby Logger.
module LoggerCompatibility

attr_accessor :formatter

# Does nothing.
def close
end
Expand All @@ -20,9 +23,30 @@ def add(level, *args)
[args[0], default_options['facility']]
end

hash = {'short_message' => message, 'facility' => progname}
if message.is_a?(Hash)
# Stringify keys.
hash = {}
message.each do |k,v|
hash[k.to_s] = message[k]
end

hash['facility'] = progname
else
hash = {'short_message' => message, 'facility' => progname}
end

hash['facility'] = default_options['facility'] unless progname

hash.merge!(self.class.extract_hash_from_exception(message)) if message.is_a?(Exception)
notify_with_level(level, hash)

if default_options['tags']
tags = current_tags
default_options['tags'].each_with_index do |tag_name, index|
hash.merge!("_#{tag_name}" => tags[index]) if tags[index]
end
end

notify_with_level(level, format_message(level, Time.now, progname, hash))
end

# Redefines methods in +Notifier+.
Expand All @@ -42,13 +66,42 @@ def #{const.downcase}? # def debug?
def <<(message)
notify_with_level(GELF::UNKNOWN, 'short_message' => message)
end

def tagged(*new_tags)
tags = current_tags
new_tags = new_tags.flatten.reject(&:blank?)
tags.concat new_tags
yield self
ensure
tags.pop(new_tags.size)
end

def current_tags
Thread.current[:gelf_tagged_logging_tags] ||= []
end

def format_message(severity, datetime, progname, message)
return message if formatter.nil?
formatter.call(severity, datetime, progname, message)
end

end

# Graylog2 notifier, compatible with Ruby Logger.
# You can use it with Rails like this:
# config.logger = GELF::Logger.new("localhost", 12201, "WAN", { :facility => "appname" })
# config.colorize_logging = false
#
# Tagged logging (with tags from rack middleware) (order of tags is important)
# Adds custom gelf messages: { '_uuid_name' => <uuid>, '_remote_ip_name' => <remote_ip> }
# config.log_tags = [:uuid, :remote_ip]
# config.colorize_logging = false
# config.logger = GELF::Logger.new("localhost", 12201, 'LAN', {
# tags: [:uuid_name, :remote_ip_name], # same order as config.log_tags
# facility: 'Jobmensa 2'
# })
class Logger < Notifier
include LoggerCompatibility
end

end
Loading