strftime_logger 0.0.1 → 0.0.2

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
2
  SHA1:
3
- metadata.gz: 9329428c0cbb2bf7dc2d5589e420659a86d5ada4
4
- data.tar.gz: 729cc3eacd69620002f9aadaff0cb138d288f22c
3
+ metadata.gz: 5ccf12099be5e2b587c5afc7748143358284427b
4
+ data.tar.gz: 1e8e3a223b1cf6e18fa7257dec026577dc84f6b7
5
5
  SHA512:
6
- metadata.gz: c4e88ff564ef06cb8ebed2571958f70f326fbd3330e65ca4056fd92283e35ea72764d20b517abd896a310cd260de95b8cc429c15422115b3f5ddaafeaaa45f32
7
- data.tar.gz: 1f0fadbd16716c2aeb5af9c7de6b5026359eafbeb0ad4128dc007f0525fd1b33fcef0004c5bc87e1702c95c1339a58df106ea594146abda40e86f56a812104e6
6
+ metadata.gz: b433ff7022ecb60477351c6ecbbe371c08aa1fbe7c0fd8f2e753bb69b1608940b6d33698583e1ed863d86b8469c02bfc894dcea1d412dc2afa78bd606ecb7917
7
+ data.tar.gz: 7b91de115753c90f49af546a072cf76ebd656e1ae9d32ab7654fe062a7c03e527658ab74910349113d03614ea271e034df36070c1167a6aa214d4e6c8fc2e92f
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1
5
+ gemfile:
6
+ - Gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.0.2 (2014/07/14)
2
+
3
+ Enhancements:
4
+
5
+ * Add time field for ltsv_formatter
6
+ * Add `#log_level=` setter
7
+
1
8
  # 0.0.1 (2014/07/01)
2
9
 
3
10
  First version
data/README.md CHANGED
@@ -4,8 +4,8 @@ A logger treats log rotation in strftime fashion.
4
4
 
5
5
  ## What is this for?
6
6
 
7
- This logger provides a feature to rotate logs in the basis of time although
8
- the ruby's built-in logger has a feature to rotate logs in the basis of log size.
7
+ The ruby's built-in logger does log rotation in the basis of log size.
8
+ In contrast, `StrftimeLogger` provides a feature to rotate logs in the basis of time.
9
9
 
10
10
  This logger allows to specify the log path with `strftime` format such as:
11
11
 
@@ -15,8 +15,9 @@ logger = StrftimeLogger.new('/var/log/application.log.%Y%m%d')
15
15
 
16
16
  which enables to rotate logs in each specific time.
17
17
 
18
- In facts, this logger does not rotate logs, but just outputs to the strftime formatted path directly,
19
- which results in avoiding locking files in log rotation.
18
+ In fact, this logger does not rotate logs, but outputs to the strftime formatted path directly.
19
+
20
+ This characteristic gives a side effect that it does not require to lock files in log rotation.
20
21
 
21
22
  ## Installation
22
23
 
@@ -53,6 +54,12 @@ are replaced with `\\n` so that the log message will be in one line.
53
54
  logger.level = StrftimeLogger::WARN
54
55
  ```
55
56
 
57
+ Or, short-hand:
58
+
59
+ ```
60
+ logger.log_level = 'WARN'
61
+ ```
62
+
56
63
  ### Change the Formatter
57
64
 
58
65
  It is possible to change the logger formmater as:
@@ -84,6 +91,10 @@ class SampleFormatter
84
91
  end
85
92
  ```
86
93
 
94
+ ## ToDo
95
+
96
+ * Support datetime_format
97
+
87
98
  ## ChangeLog
88
99
 
89
100
  See [CHANGELOG.md](CHANGELOG.md) for details.
data/Rakefile CHANGED
@@ -12,6 +12,6 @@ end
12
12
 
13
13
  desc 'Open an irb session preloaded with the gem library'
14
14
  task :console do
15
- sh 'irb -rubygems -I lib -r pfsys-logger'
15
+ sh 'irb -rubygems -I lib -r strftime_logger'
16
16
  end
17
17
  task :c => :console
@@ -82,6 +82,21 @@ class StrftimeLogger
82
82
  end
83
83
  end
84
84
 
85
+ def level=(level)
86
+ raise ArgumentError, 'An argument for #level= must be an Integer such as 0, 2. You may use Pfsys::Logger::DEBUG, Pfsys::Logger::WARN' unless level.is_a?(Integer)
87
+ @level = level
88
+ end
89
+
90
+ def self.str_to_level(str)
91
+ level = SEV_LABEL.index(str.to_s.downcase.to_sym)
92
+ raise ArgumentError, 'An argument for #log_level= must be a String or Symbol such as DEBUG, :warn' unless level
93
+ level
94
+ end
95
+
96
+ def log_level=(log_level)
97
+ @level = self.class.str_to_level(log_level)
98
+ end
99
+
85
100
  # @param severity [Int] log severity
86
101
  def add(severity, message = nil, &block)
87
102
  severity ||= UNKNOWN
@@ -126,7 +141,7 @@ class StrftimeLogger
126
141
 
127
142
  def write(msg)
128
143
  msg.chomp! if msg.respond_to?(:chomp!)
129
- add(INFO, msg)
144
+ @bridge[:info].write(format_message(nil, msg))
130
145
  end
131
146
 
132
147
  # Returns +true+ iff the current severity level allows for the printing of
@@ -16,7 +16,11 @@ class StrftimeLogger
16
16
  message = ""
17
17
  end
18
18
  end
19
- FORMAT % [format_datetime(Time.now), format_severity(severity), format_message(message)]
19
+ if severity.nil?
20
+ format_message(message) + "\n"
21
+ else
22
+ FORMAT % [format_datetime(Time.now), format_severity(severity), format_message(message)]
23
+ end
20
24
  end
21
25
 
22
26
  private
@@ -13,7 +13,8 @@ class StrftimeLogger
13
13
  message = ""
14
14
  end
15
15
  end
16
- "#{format_message(message)}\n"
16
+ time = Time.now.iso8601
17
+ "time:#{time}\t#{format_message(message)}\n"
17
18
  end
18
19
 
19
20
  private
@@ -18,6 +18,19 @@ describe StrftimeLogger do
18
18
  Timecop.return
19
19
  end
20
20
 
21
+ it :info do
22
+ subject.info("test")
23
+ begin
24
+ raise ArgumentError.new('test')
25
+ rescue => e
26
+ subject.info(e)
27
+ end
28
+ File.open("#{log_dir}/application.log.#{today}") do |f|
29
+ expect(f.gets).to eq "#{now} [INFO] test\n"
30
+ expect(f.gets).to match(/#{Regexp.escape(now)} \[INFO\] ArgumentError test/)
31
+ end
32
+ end
33
+
21
34
  it :write do
22
35
  subject.write("test")
23
36
  begin
@@ -26,8 +39,8 @@ describe StrftimeLogger do
26
39
  subject.write(e)
27
40
  end
28
41
  File.open("#{log_dir}/application.log.#{today}") do |f|
29
- expect(f.gets).to eq "#{now} [INFO] test\n"
30
- expect(f.gets).to match(/#{Regexp.escape(now)} \[INFO\] ArgumentError test/)
42
+ expect(f.gets).to eq "test\n"
43
+ expect(f.gets).to match(/ArgumentError test/)
31
44
  end
32
45
  end
33
46
  end
@@ -10,6 +10,7 @@ describe StrftimeLogger do
10
10
  end
11
11
  let(:log_dir) { "#{File.dirname(__FILE__)}/log" }
12
12
  let(:today) { Time.now.strftime "%Y%m%d"}
13
+ let(:now) { Time.now.iso8601 }
13
14
 
14
15
  before do
15
16
  Dir.mkdir(log_dir)
@@ -25,8 +26,8 @@ describe StrftimeLogger do
25
26
  subject.write("test")
26
27
  subject.write({a:1, b:2})
27
28
  File.open("#{log_dir}/application.log.#{today}") do |f|
28
- expect(f.gets).to eq "message:test\n"
29
- expect(f.gets).to eq "a:1\tb:2\n"
29
+ expect(f.gets).to eq "time:#{now}\tmessage:test\n"
30
+ expect(f.gets).to eq "time:#{now}\ta:1\tb:2\n"
30
31
  end
31
32
  end
32
33
  end
@@ -23,7 +23,7 @@ describe StrftimeLogger do
23
23
  it :write do
24
24
  subject.write("test")
25
25
  subject.write("test")
26
- expect(File.read("#{log_dir}/application.log.#{today}")).to eq "#{now} [INFO] test\n"*2
26
+ expect(File.read("#{log_dir}/application.log.#{today}")).to eq "test\n"*2
27
27
  end
28
28
 
29
29
  LEVEL_TEXT = %w(DEBUG INFO WARN ERROR FATAL UNKNOWN)
@@ -81,6 +81,14 @@ describe StrftimeLogger do
81
81
  expect(File.read("#{log_dir}/application.log")).to eq "#{now} [WARN] test\n"
82
82
  end
83
83
 
84
+ it 'log_level=' do
85
+ logger = StrftimeLogger.new("#{log_dir}/application.log")
86
+ logger.log_level = 'WARN'
87
+ logger.info("test")
88
+ logger.warn("test")
89
+ expect(File.read("#{log_dir}/application.log")).to eq "#{now} [WARN] test\n"
90
+ end
91
+
84
92
  class MockAdapter
85
93
  def initialize(level, path)
86
94
  end
@@ -4,9 +4,9 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "strftime_logger"
7
- gem.version = "0.0.1"
7
+ gem.version = "0.0.2"
8
8
  gem.authors = ["Naotoshi Seo"]
9
- gem.email = ["seo.naotoshi@dena.jp"]
9
+ gem.email = ["sonots@gmail.com"]
10
10
  gem.description = %q{A logger treats log rotation in strftime fashion}
11
11
  gem.summary = %q{A logger treats log rotation in strftime fashion.}
12
12
  gem.homepage = "https://github.com/sonots/strftime-logger"
metadata CHANGED
@@ -1,23 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strftime_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-01 00:00:00.000000000 Z
11
+ date: 2014-07-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A logger treats log rotation in strftime fashion
14
14
  email:
15
- - seo.naotoshi@dena.jp
15
+ - sonots@gmail.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - ".gitignore"
21
+ - ".travis.yml"
21
22
  - CHANGELOG.md
22
23
  - Gemfile
23
24
  - LICENSE.txt
@@ -56,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  version: '0'
57
58
  requirements: []
58
59
  rubyforge_project:
59
- rubygems_version: 2.2.2
60
+ rubygems_version: 2.2.0
60
61
  signing_key:
61
62
  specification_version: 4
62
63
  summary: A logger treats log rotation in strftime fashion.