applicaster-logger 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/applicaster-logger.gemspec +26 -0
- data/lib/applicaster-logger.rb +1 -0
- data/lib/applicaster/logger.rb +34 -0
- data/lib/applicaster/logger/formatter.rb +57 -0
- data/lib/applicaster/logger/railtie.rb +23 -0
- data/lib/applicaster/logger/version.rb +5 -0
- metadata +121 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Vitaly Gorodetsky
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# ApplicasterLogger
|
2
|
+
|
3
|
+
Dispatches all Rails and DelayedJob log events to logstash
|
4
|
+
|
5
|
+
Combines [Lograge](https://github.com/roidrage/lograge) with [logstash-logger](https://github.com/dwbutler/logstash-logger)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'applicaster-logger'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
1. Enable it for the relevant environments, e.g. production:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# config/environments/production.rb
|
23
|
+
MyApp::Application.configure do
|
24
|
+
config.applicaster_logger.enabled = true
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
2. Configuring logstash output:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# config/environments/production.rb
|
32
|
+
MyApp::Application.configure do
|
33
|
+
config.applicaster_logger.logstash_config = { type: :redis }
|
34
|
+
end
|
35
|
+
```
|
36
|
+
defaults to: `{ type: :stdout }`
|
37
|
+
|
38
|
+
For availible options see: https://github.com/dwbutler/logstash-logger#basic-usage
|
39
|
+
|
40
|
+
3. To set the application name:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# config/environments/production.rb
|
44
|
+
MyApp::Application.configure do
|
45
|
+
config.applicaster_logger.application_name = "my_best_app"
|
46
|
+
end
|
47
|
+
```
|
48
|
+
defaults to: `Rails.application.class.parent.to_s.underscore`
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'applicaster/logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "applicaster-logger"
|
8
|
+
spec.version = Applicaster::Logger::VERSION
|
9
|
+
spec.authors = ["Vitaly Gorodetsky"]
|
10
|
+
spec.email = ["v.gorodetsky@applicaster.com"]
|
11
|
+
spec.description = %q{ Applicaster Logger configurator }
|
12
|
+
spec.summary = %q{ Configures loggers to send logs to logstash }
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'logstash-logger'
|
22
|
+
spec.add_dependency 'lograge'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'applicaster/logger'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "applicaster/logger/version"
|
2
|
+
require "applicaster/logger/railtie"
|
3
|
+
require "applicaster/logger/formatter"
|
4
|
+
|
5
|
+
module Applicaster
|
6
|
+
module Logger
|
7
|
+
def self.setup_lograge(app)
|
8
|
+
app.config.lograge.enabled = true
|
9
|
+
app.config.lograge.formatter = Lograge::Formatters::Logstash.new
|
10
|
+
app.config.lograge.custom_options = lambda do |event|
|
11
|
+
{
|
12
|
+
params: event.payload[:params].except('controller', 'action', 'format'),
|
13
|
+
facility: "action_controller",
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.setup_logger(app)
|
19
|
+
logstash_config = app.config.applicaster_logger.logstash_config
|
20
|
+
|
21
|
+
app.config.logger = LogStashLogger.new(logstash_config)
|
22
|
+
app.config.logger.level = app.config.applicaster_logger.level
|
23
|
+
app.config.logger.formatter =
|
24
|
+
Applicaster::Logger::Formatter.new(facility: "rails_logger")
|
25
|
+
|
26
|
+
if defined?(Delayed)
|
27
|
+
Delayed::Worker.logger = LogStashLogger.new(logstash_config)
|
28
|
+
Delayed::Worker.logger.level = app.config.applicaster_logger.level
|
29
|
+
Delayed::Worker.logger.formatter =
|
30
|
+
Applicaster::Logger::Formatter.new(facility: "delayed_job")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'socket'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Applicaster
|
6
|
+
module Logger
|
7
|
+
HOST = ::Socket.gethostname
|
8
|
+
|
9
|
+
class Formatter < ::Logger::Formatter
|
10
|
+
include LogStashLogger::TaggedLogging::Formatter
|
11
|
+
|
12
|
+
attr_accessor :facility
|
13
|
+
|
14
|
+
def initialize(options = {})
|
15
|
+
@facility = options[:facility]
|
16
|
+
@datetime_format = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(severity, time, progname, message)
|
20
|
+
build_event(message, severity, time)
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def build_event(message, severity, time)
|
26
|
+
data = JSON.parse(message).symbolize_keys rescue nil if message.is_a?(String)
|
27
|
+
data ||= message
|
28
|
+
|
29
|
+
event =
|
30
|
+
case data
|
31
|
+
when LogStash::Event
|
32
|
+
data.clone
|
33
|
+
when Hash
|
34
|
+
LogStash::Event.new(data.merge("@timestamp" => time))
|
35
|
+
else
|
36
|
+
LogStash::Event.new(message: msg2str(data), "@timestamp" => time)
|
37
|
+
end
|
38
|
+
|
39
|
+
event[:severity] ||= severity
|
40
|
+
event[:host] ||= HOST
|
41
|
+
event[:application] ||= Rails.application.config.applicaster_logger.application_name
|
42
|
+
event[:environment] ||= Rails.env
|
43
|
+
event[:facility] ||= facility
|
44
|
+
|
45
|
+
current_tags.each do |tag|
|
46
|
+
event.tag(tag)
|
47
|
+
end
|
48
|
+
|
49
|
+
# In case Time#to_json has been overridden
|
50
|
+
if event.timestamp.is_a?(Time)
|
51
|
+
event.timestamp = event.timestamp.iso8601(3)
|
52
|
+
end
|
53
|
+
"#{event.to_json}\n"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
require 'lograge'
|
3
|
+
require 'logstash-logger'
|
4
|
+
|
5
|
+
module Applicaster
|
6
|
+
module Logger
|
7
|
+
class Railtie < Rails::Railtie
|
8
|
+
config.applicaster_logger = ActiveSupport::OrderedOptions.new
|
9
|
+
config.applicaster_logger.enabled = false
|
10
|
+
config.applicaster_logger.level = ::Logger::INFO
|
11
|
+
config.applicaster_logger.logstash_config = { type: :stdout }
|
12
|
+
config.applicaster_logger.application_name = Rails.application.class.parent.to_s.underscore
|
13
|
+
|
14
|
+
initializer :applicaster_logger_lograge, before: :lograge do |app|
|
15
|
+
Applicaster::Logger.setup_lograge(app) if app.config.applicaster_logger.enabled
|
16
|
+
end
|
17
|
+
|
18
|
+
initializer :applicaster_logger, before: :initialize_logger do |app|
|
19
|
+
Applicaster::Logger.setup_logger(app) if app.config.applicaster_logger.enabled
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: applicaster-logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vitaly Gorodetsky
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-10-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: logstash-logger
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: lograge
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: ! ' Applicaster Logger configurator '
|
79
|
+
email:
|
80
|
+
- v.gorodetsky@applicaster.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- applicaster-logger.gemspec
|
91
|
+
- lib/applicaster-logger.rb
|
92
|
+
- lib/applicaster/logger.rb
|
93
|
+
- lib/applicaster/logger/formatter.rb
|
94
|
+
- lib/applicaster/logger/railtie.rb
|
95
|
+
- lib/applicaster/logger/version.rb
|
96
|
+
homepage: ''
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 1.8.23
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: Configures loggers to send logs to logstash
|
121
|
+
test_files: []
|