act-fluent-logger-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in act-fluent-logger-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yoshinori Tahara
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.
@@ -0,0 +1,32 @@
1
+ # Act::Fluent::Logger::Rails
2
+
3
+ Fluent logger.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'act-fluent-logger-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install act-fluent-logger-rails
18
+
19
+ ## Usage
20
+
21
+ in config/environments/production.rb
22
+
23
+ config.log_level = :info
24
+ config.logger = Actindi::Logger.new
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'act-fluent-logger-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "act-fluent-logger-rails"
8
+ gem.version = ActFluentLoggerRails::VERSION
9
+ gem.authors = ["Yoshinori Tahara"]
10
+ gem.email = ["read.eval.print@gmail.com"]
11
+ gem.description = %q{Fluent logger}
12
+ gem.summary = %q{Fluent logger}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rspec"
21
+ gem.add_runtime_dependency "fluent-logger"
22
+ gem.add_runtime_dependency "rails"
23
+ end
@@ -0,0 +1,2 @@
1
+ require "act-fluent-logger-rails/version"
2
+ require "act-fluent-logger-rails/logger"
@@ -0,0 +1,76 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'fluent-logger'
3
+
4
+ module ActFluentLoggerRails
5
+
6
+ class Logger < ::ActiveSupport::TaggedLogging
7
+ def initialize
8
+ config_file = Rails.root.join("config", "fluent-logger.yml")
9
+ fluent_config = YAML.load(ERB.new(config_file.read).result)[Rails.env]
10
+ settings = {
11
+ tag: fluent_config['tag'],
12
+ host: fluent_config['fluent_host'],
13
+ port: fluent_config['fluent_port']
14
+ }
15
+ @level = SEV_LABEL.index(Rails.application.config.log_level.to_s.upcase)
16
+ super(::Actindi::FluentLogger.new(settings, @level))
17
+ end
18
+
19
+ def add(severity, message = nil, progname = nil, &block)
20
+ return true if severity < @level
21
+ message = (block_given? ? block.call : progname) if message.blank?
22
+ return true if message.blank?
23
+ @logger.add_message(severity, message)
24
+ true
25
+ end
26
+
27
+ def tagged(*tags)
28
+ super(*tags)
29
+ ensure
30
+ @logger.flush
31
+ end
32
+
33
+ # Severity label for logging. (max 5 char)
34
+ SEV_LABEL = %w(DEBUG INFO WARN ERROR FATAL ANY)
35
+ end
36
+
37
+ class FluentLogger < ActiveSupport::BufferedLogger
38
+ def initialize(options, level=DEBUG)
39
+ self.level = level
40
+ port = options[:port]
41
+ host = options[:host]
42
+ @tag = options[:tag]
43
+ @fluent_logger = ::Fluent::Logger::FluentLogger.new(nil, host: host, port: port)
44
+ @severity = 0
45
+ @messages = []
46
+ end
47
+
48
+ def add_message(severity, message)
49
+ @severity = severity if @severity < severity
50
+ @messages << message
51
+ end
52
+
53
+ def flush
54
+ return if @messages.empty?
55
+ @fluent_logger.post(@tag, messages: @messages, level: format_severity(@severity))
56
+ @severity = 0
57
+ @messages.clear
58
+ end
59
+
60
+ def close
61
+ @fluent_logger.close
62
+ end
63
+
64
+ def level
65
+ @level
66
+ end
67
+
68
+ def level=(l)
69
+ @level = l
70
+ end
71
+
72
+ def format_severity(severity)
73
+ Actindi::Logger::SEV_LABEL[severity] || 'ANY'
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module ActFluentLoggerRails
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: act-fluent-logger-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yoshinori Tahara
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
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: fluent-logger
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: rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Fluent logger
63
+ email:
64
+ - read.eval.print@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - act-fluent-logger-rails.gemspec
75
+ - lib/act-fluent-logger-rails.rb
76
+ - lib/act-fluent-logger-rails/logger.rb
77
+ - lib/act-fluent-logger-rails/version.rb
78
+ homepage: ''
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.24
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Fluent logger
102
+ test_files: []