logger_extension 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ todo.txt
2
+ .rspec
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logger_extension.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 kuldeepaggarwal
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,29 @@
1
+ # LoggerExtension
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'logger_extension'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install logger_extension
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
File without changes
@@ -0,0 +1,65 @@
1
+ require 'monitor'
2
+ require 'logger_extension/formatter'
3
+
4
+ module LoggerExtension
5
+ class MultiIOLogger
6
+
7
+ class LogDeviceMutex
8
+ include MonitorMixin
9
+ end
10
+
11
+ attr_reader :default_formatter
12
+ attr_accessor :default_progname
13
+
14
+ def initialize(*targets)
15
+ @targets = targets
16
+ @default_formatter = ::LoggerExtension::Formatter.new
17
+ @mutex = LogDeviceMutex.new
18
+ end
19
+
20
+ def write(*arguments)
21
+ @targets.each { |target|
22
+ begin
23
+ @mutex.synchronize do
24
+ begin
25
+ target.write(*arguments)
26
+ rescue
27
+ log_exception('WARN', 'log writing failed.--->', $!)
28
+ end
29
+ end
30
+ rescue Exception => ignored
31
+ log_exception('WARN', 'log writing failed.--->', ignored)
32
+ end
33
+ }
34
+ end
35
+
36
+ def close
37
+ @targets.each do |target|
38
+ begin
39
+ @mutex.synchronize do
40
+ target.close rescue nil
41
+ end
42
+ rescue Exception
43
+ target.close rescue nil
44
+ end
45
+ end
46
+ end
47
+
48
+ def datetime_format
49
+ default_formatter.datetime_format
50
+ end
51
+
52
+ def datetime_format=(format)
53
+ default_formatter.datetime_format = format
54
+ end
55
+
56
+ private
57
+ def log_exception(severity, message, exception)
58
+ write_message(message.to_s + default_formatter.call(severity, Time.now, default_progname, exception).to_s)
59
+ end
60
+
61
+ def write_message(message)
62
+ STDOUT.write message
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,34 @@
1
+ module LoggerExtension
2
+ class Formatter
3
+ Format = "\n#{ '#' * 143 }\n[%s], [%s] %5s:\n %s\n#{ '#' * 143 }\n"
4
+ DEFAULT_FORMAT = '%Y-%m-%d %H:%M:%S'
5
+
6
+ attr_accessor :datetime_format
7
+
8
+ def initialize(datetime_format = nil)
9
+ @datetime_format = datetime_format || DEFAULT_FORMAT
10
+ end
11
+
12
+ def call(severity, time, progname, msg)
13
+ Format % [progname, format_datetime(time), severity, msg2str(msg)]
14
+ end
15
+
16
+ private
17
+
18
+ def msg2str(msg)
19
+ case msg
20
+ when ::String
21
+ msg
22
+ when ::Exception
23
+ "#{ msg.message } (#{ msg.class })\n" <<
24
+ (msg.backtrace || []).join("\n")
25
+ else
26
+ msg.inspect
27
+ end
28
+ end
29
+
30
+ def format_datetime(time)
31
+ time.strftime(@datetime_format)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module LoggerExtension
2
+ VERSION = "0.0.1".freeze
3
+ end
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'logger_extension/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'logger_extension'
7
+ spec.version = LoggerExtension::VERSION
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.authors = ['kuldeepaggarwal']
10
+ spec.email = ['kd.engineer@yahoo.co.in']
11
+ spec.description = 'A utility for logging on multiple files for rack applications'
12
+ spec.summary = 'A utility for logging on multiple files for rack applications.'
13
+ spec.license = "MIT"
14
+ spec.files = `git ls-files`.split("\n")
15
+ spec.require_paths = ['lib']
16
+ spec.homepage = 'https://github.com/kuldeepaggarwal/logger_extension'
17
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logger_extension
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - kuldeepaggarwal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-15 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A utility for logging on multiple files for rack applications
15
+ email:
16
+ - kd.engineer@yahoo.co.in
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/logger_extension.rb
27
+ - lib/logger_extension/formatter.rb
28
+ - lib/logger_extension/version.rb
29
+ - logger_extension.gemspec
30
+ homepage: https://github.com/kuldeepaggarwal/logger_extension
31
+ licenses:
32
+ - MIT
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.25
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: A utility for logging on multiple files for rack applications.
55
+ test_files: []