dedicated_logger 0.0.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24f5acbfe3a2a1c8d5098ac2bca5cb3948ba63ef
4
+ data.tar.gz: a4b95d9ef7068fd492c2291c7b3c91a877ade2d0
5
+ SHA512:
6
+ metadata.gz: e3bef859f0910ff3f90c8106bb0a677e003c34cbc1dd5dd9718166a756183b88f1bc4dffe5d8028e739fca4cf33c39a5da5f8e32839850fa807dadb99b5ccd94
7
+ data.tar.gz: 847a71cbdc3bdf1cf016583b7e3349212e2b9651b64f7a1bfd2099ae7a47823a234ec76dca1f5c2ce47a82d3d9819542948ebb48069a870f88c08601b21b9bee
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 tskorupa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ dedicated_logger
2
+ ================
3
+
4
+ Used for any ruby class, perhaps running as background tasks, in desperate need of a dedicated log file with event severity and timestamp.
5
+
6
+ Installation
7
+ -----------
8
+
9
+ TODO
10
+
11
+ Usage
12
+ -----
13
+
14
+ require 'dedicated_logger'
15
+
16
+ class Foo
17
+
18
+ def self.bar
19
+ logger.info "info from class method"
20
+ logger.warn "warn from class method"
21
+ logger.error "error from class method"
22
+ logger.fatal "fatal from class method"
23
+ end
24
+
25
+ def baz
26
+ logger.info "info"
27
+ logger.warn "warn"
28
+ logger.error "error"
29
+ logger.fatal "fatal"
30
+ end
31
+
32
+ private
33
+
34
+ def logger
35
+ self.class.logger
36
+ end
37
+
38
+ def self.logger
39
+ @logger ||= DedicatedLogger.new(self, "test")
40
+ end
41
+ end
42
+
43
+ TODO
44
+ ================
45
+
46
+ * Add tests
47
+ * convert to acts_as_* module
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task default: :test
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'dedicated_logger'
5
+ s.version = '0.0.3'
6
+ s.description = %q{Output formatter for the ruby Logger class}
7
+ s.summary = %q{Standardize the logged output for background tasks and store it in a dedicated file}
8
+ s.authors = ['Tomasz Skorupa']
9
+ s.files = `git ls-files`.split($/)
10
+ s.require_paths = ['lib']
11
+
12
+ s.required_ruby_version = '>= 1.9.3'
13
+ s.add_development_dependency 'rake'
14
+ end
@@ -0,0 +1,27 @@
1
+ require 'logger'
2
+ require 'fileutils'
3
+
4
+ class DedicatedLogger < Logger
5
+
6
+ def initialize logger_name, filename, options={}
7
+ @logger_name = logger_name
8
+
9
+ log_dir = File.absolute_path(options[:log_dir] || "log")
10
+ FileUtils.mkdir_p(log_dir) unless File.exists? log_dir
11
+
12
+ super File.join(log_dir, "#{filename}.log")
13
+ end
14
+
15
+ def format_message severity, timestamp, progname, msg
16
+ msg = "#{timestamp.strftime("%Y-%m-%d %H:%M:%S")} #{@logger_name} [#{$$}] #{severity}: #{msg}\n"
17
+
18
+ if %w(WARN ERROR FATAL).include?(severity.to_s)
19
+ STDERR.puts(msg)
20
+ else
21
+ STDOUT.puts(msg)
22
+ end
23
+
24
+ msg
25
+ end
26
+
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'minitest/autorun'
2
+ require 'dedicated_logger'
3
+
4
+ class DedicatedLoggerTest < MiniTest::Unit::TestCase
5
+
6
+ def setup
7
+ @logger = DedicatedLogger.new("TEST", "test")
8
+ end
9
+
10
+ def test_instantiation
11
+ assert_kind_of DedicatedLogger, @logger
12
+ end
13
+
14
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dedicated_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Tomasz Skorupa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Output formatter for the ruby Logger class
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - Rakefile
36
+ - dedicated_logger.gemspec
37
+ - lib/dedicated_logger.rb
38
+ - test/test_dedicated_logger.rb
39
+ homepage:
40
+ licenses: []
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: 1.9.3
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.0.14
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Standardize the logged output for background tasks and store it in a dedicated
62
+ file
63
+ test_files: []