multi_logger 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7781fb7ec45c05fd258ffd68a4fa97e5a892133f
4
- data.tar.gz: 8b735244380af2fcd0b781ddafea50d05be2a183
2
+ SHA256:
3
+ metadata.gz: 53105078b9d403fe26d8adcb8544c7c0c181d0eef00b87412057aab5334c4659
4
+ data.tar.gz: 386f88badfc3ec2d1bd42237c05784f246e18274627d38584b4d9d0833ee4c49
5
5
  SHA512:
6
- metadata.gz: 436ffcf55924ee88d289f3b04f32ba698d35499cdb2fd1c9467c1938474eb20480f86dd9248b34ab4877383f072873b0140f453623c1e2287459a6c6148b7fce
7
- data.tar.gz: e2501ae314f9c04e8e79f7cd74685e2b2993337c242e88317c935f635d893c2f209ab1694bb8b484bb56a9d7f5d988cef35af355d6311a4e435d9c77122989ea
6
+ metadata.gz: d9d2c806a7b3d5f209c505f959e99dba69006282be0dbe730122676997dc893776f5b6f16e98f1eb49e2c7b5c9779d1977a7e1a7cc7cbf0fd4d64e548d533cd0
7
+ data.tar.gz: 6c8383fe6ca11389dd45e17e519a9cf38a568b7d98286ddf36aa3aa4911bebffbd5ee92f9171fb6e019b9da83d66400a5de8939d4352132fde319031cddc5716
data/CHANGES.md CHANGED
@@ -1,9 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## 0.2.0 - 2020/07/14
4
+
5
+ * [Enhancement] Accept `STDOUT` as log path - Konstantin
6
+
3
7
  ## 0.1.0 - 2013/09/13
4
8
 
5
9
  * [Enhancement] Accept `shift_age` and `shift size` as an argument to the `Logger.new` - Keisuke KITA
6
10
 
7
11
  ## 0.0.1 - 2013/05/30
8
12
 
9
- * Initial publication
13
+ * Initial publication
data/README.md CHANGED
@@ -44,6 +44,12 @@ You can assign formatter to loggers directly, or pass the formatter during setup
44
44
  MultiLogger.add_logger('mail', formatter:formatter)
45
45
  MultiLogger.add_logger('user', formatter:formatter)
46
46
 
47
+ To set a different path to the log file, use `:path` option.
48
+ For example, for setting a different file to each environment use:
49
+
50
+ MultiLogger.add_logger('mail', formatter:formatter, path:"mail_#{Rails.env}")
51
+
52
+
47
53
  ## Contributing
48
54
 
49
55
  1. Fork it
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "lib"
6
+ t.libs.push "spec"
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ t.verbose = true
9
+ end
@@ -6,24 +6,23 @@ module MultiLogger
6
6
  name = name.to_s
7
7
  rails_logger_class = get_rails_logger_class()
8
8
 
9
- if rails_logger_class.method_defined?(name)
10
- raise "'#{name}' is reserved in #{rails_logger_class} and can not be used as a log accessor name."
11
- else
12
- logger = Logger.new(*extract_options(name, options))
13
- rails_logger_class.class_eval do
14
- define_method name.to_sym do
15
- logger
16
- end
17
- end
18
- if options[:formatter]
19
- logger.formatter = options[:formatter]
9
+ raise "'#{name}' is reserved in #{rails_logger_class} and can not be used as a log accessor name." if rails_logger_class.method_defined?(name)
10
+
11
+ logger = Logger.new(*extract_options(name, options))
12
+ rails_logger_class.class_eval do
13
+ define_method name.to_sym do
14
+ logger
20
15
  end
21
- logger
22
16
  end
17
+
18
+ logger.formatter = options[:formatter] if options[:formatter]
19
+ logger
23
20
  end
24
21
 
25
22
  # Computes log file path
26
23
  def get_path(name, path=nil)
24
+ return path if path == STDOUT
25
+
27
26
  if path.nil?
28
27
  path = name.underscore
29
28
  end
@@ -47,13 +46,15 @@ module MultiLogger
47
46
  end
48
47
 
49
48
  def extract_options(name, options)
49
+ path = get_path(name, options[:path])
50
+
50
51
  if options[:shift_age] && options[:shift_size]
51
- [get_path(name, options[:path]), options[:shift_age], options[:shift_size]]
52
+ [path, options[:shift_age], options[:shift_size]]
52
53
  elsif options[:shift_age]
53
54
  # options[:shift_age] => 'daily', 'weekly'
54
- [get_path(name, options[:path]), options[:shift_age]]
55
+ [path, options[:shift_age]]
55
56
  else
56
- [get_path(name, options[:path])]
57
+ [path]
57
58
  end
58
59
  end
59
60
  end
@@ -1,3 +1,3 @@
1
1
  module MultiLogger
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ class << self
3
+ def loggers
4
+ MultiLogger
5
+ end
6
+ end
7
+ end
@@ -19,4 +19,6 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_dependency 'railties'
22
+ gem.add_development_dependency "activesupport"
23
+ gem.add_development_dependency "mocha"
22
24
  end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'bundler'
5
+ rescue LoadError => e
6
+ STDERR.puts e.message
7
+ STDERR.puts "Run `gem install bundler` to install Bundler."
8
+ exit e.status_code
9
+ end
10
+
11
+ begin
12
+ Bundler.setup(:default, :development, :test)
13
+ rescue Bundler::BundlerError => e
14
+ STDERR.puts e.message
15
+ STDERR.puts "Run `bundle install` to install missing gems."
16
+ exit e.status_code
17
+ end
18
+
19
+ require 'minitest/autorun'
20
+ require 'minitest/spec'
21
+ require "mocha/mini_test"
File without changes
@@ -0,0 +1,66 @@
1
+ require 'helper'
2
+ require 'multi_logger'
3
+
4
+ require 'logger'
5
+ require 'active_support/core_ext/string'
6
+
7
+ # Dummy class to avoid loading Rails
8
+ module Rails
9
+ def self.root
10
+ Pathname.new('./spec/')
11
+ end
12
+ end
13
+
14
+ describe MultiLogger do
15
+ it 'has version' do
16
+ MultiLogger.const_get('VERSION').wont_be_empty
17
+ end
18
+
19
+ describe '.add_logger' do
20
+ it 'raises error if name already in use as method name' do
21
+ lambda { MultiLogger.add_logger('object_id') }.must_raise RuntimeError
22
+ end
23
+ it 'defines a instance method in Rails Logger class linking to custom logger' do
24
+ rails_logger_klass = Class.new
25
+ MultiLogger.stubs(:get_rails_logger_class).returns(rails_logger_klass)
26
+
27
+ logger = Logger.new('test')
28
+ Logger.stubs(:new).returns(logger)
29
+
30
+ MultiLogger.add_logger('payment').must_equal logger
31
+
32
+ rails_logger_klass.new.payment.must_equal logger
33
+ end
34
+ it 'assigns formatter to custom logger' do
35
+ rails_logger_klass = Class.new
36
+ MultiLogger.stubs(:get_rails_logger_class).returns(rails_logger_klass)
37
+
38
+ logger = Logger.new('test')
39
+ Logger.stubs(:new).returns(logger)
40
+
41
+ formatter = mock('formatter')
42
+ MultiLogger.add_logger('fb',{formatter:formatter}).must_equal logger
43
+
44
+ rails_logger_klass.new.fb.must_equal logger
45
+ logger.formatter.must_equal formatter
46
+ end
47
+ end
48
+
49
+ describe '.get_path' do
50
+ it '' do
51
+ MultiLogger.send(:get_path,'parser').to_s.must_equal './spec/log/parser.log'
52
+ end
53
+ it 'uses path as file path different to name' do
54
+ MultiLogger.send(:get_path,'fb','facebook').to_s.must_equal './spec/log/facebook.log'
55
+ end
56
+ it 'uses path as file path (relative to Rails root) different to name' do
57
+ MultiLogger.send(:get_path,'fb','facebook').to_s.must_equal './spec/log/facebook.log'
58
+ end
59
+ it 'uses path as file path as is if it contains slash' do
60
+ MultiLogger.send(:get_path,'fb','./facebook').to_s.must_equal './facebook.log'
61
+ end
62
+ it 'does not append .log if path already ends with it' do
63
+ MultiLogger.send(:get_path,'fb','./facebook.log').to_s.must_equal './facebook.log'
64
+ end
65
+ end
66
+ end
metadata CHANGED
@@ -1,27 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lulalala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-13 00:00:00.000000000 Z
11
+ date: 2020-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
25
53
  - !ruby/object:Gem::Version
26
54
  version: '0'
27
55
  description: Create multiple loggers in Rails.
@@ -31,7 +59,7 @@ executables: []
31
59
  extensions: []
32
60
  extra_rdoc_files: []
33
61
  files:
34
- - .gitignore
62
+ - ".gitignore"
35
63
  - CHANGES.md
36
64
  - Gemfile
37
65
  - LICENSE.txt
@@ -39,7 +67,11 @@ files:
39
67
  - Rakefile
40
68
  - lib/multi_logger.rb
41
69
  - lib/multi_logger/version.rb
70
+ - lib/railties/lib/rails.rb
42
71
  - multi_logger.gemspec
72
+ - spec/helper.rb
73
+ - spec/log/.gitkeep
74
+ - spec/multi_logger_spec.rb
43
75
  homepage: https://github.com/lulalala/multi_logger
44
76
  licenses: []
45
77
  metadata: {}
@@ -49,20 +81,21 @@ require_paths:
49
81
  - lib
50
82
  required_ruby_version: !ruby/object:Gem::Requirement
51
83
  requirements:
52
- - - '>='
84
+ - - ">="
53
85
  - !ruby/object:Gem::Version
54
86
  version: '0'
55
87
  required_rubygems_version: !ruby/object:Gem::Requirement
56
88
  requirements:
57
- - - '>='
89
+ - - ">="
58
90
  - !ruby/object:Gem::Version
59
91
  version: '0'
60
92
  requirements: []
61
- rubyforge_project:
62
- rubygems_version: 2.0.5
93
+ rubygems_version: 3.1.3
63
94
  signing_key:
64
95
  specification_version: 4
65
96
  summary: Provide helper to define loggers and access them. Each logger will log into
66
97
  a different file under the log folder.
67
- test_files: []
68
- has_rdoc:
98
+ test_files:
99
+ - spec/helper.rb
100
+ - spec/log/.gitkeep
101
+ - spec/multi_logger_spec.rb