yell 1.4.0 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -2
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +16 -13
  5. data/Gemfile +15 -8
  6. data/LICENSE.txt +1 -1
  7. data/README.md +10 -3
  8. data/Rakefile +1 -3
  9. data/examples/002.1-log-level-basics.rb +2 -2
  10. data/examples/002.2-log-level-on-certain-severities-only.rb +5 -4
  11. data/examples/002.3-log-level-within-range.rb +7 -5
  12. data/examples/003.1-formatting-DefaultFormat.rb +3 -3
  13. data/examples/003.2-formatting-BasicFormat.rb +3 -3
  14. data/examples/003.3-formatting-ExtendedFormat.rb +3 -3
  15. data/examples/003.4-formatting-on-your-own.rb +3 -3
  16. data/examples/004.1-colorizing-the-log-output.rb +3 -3
  17. data/examples/005.1-repository.rb +3 -3
  18. data/examples/006.1-the-loggable-module.rb +2 -2
  19. data/examples/006.2-the-loggable-module-with-inheritance.rb +2 -2
  20. data/lib/core_ext/logger.rb +17 -0
  21. data/lib/yell/adapters/base.rb +17 -22
  22. data/lib/yell/adapters/datefile.rb +23 -22
  23. data/lib/yell/adapters/file.rb +3 -7
  24. data/lib/yell/adapters/io.rb +9 -15
  25. data/lib/yell/adapters/streams.rb +0 -5
  26. data/lib/yell/adapters.rb +41 -10
  27. data/lib/yell/configuration.rb +2 -4
  28. data/lib/yell/event.rb +46 -10
  29. data/lib/yell/formatter.rb +134 -54
  30. data/lib/yell/helpers/{adapters.rb → adapter.rb} +7 -17
  31. data/lib/yell/helpers/base.rb +0 -1
  32. data/lib/yell/helpers/formatter.rb +8 -8
  33. data/lib/yell/helpers/level.rb +7 -4
  34. data/lib/yell/helpers/silencer.rb +3 -5
  35. data/lib/yell/helpers/tracer.rb +6 -7
  36. data/lib/yell/level.rb +19 -16
  37. data/lib/yell/loggable.rb +11 -7
  38. data/lib/yell/logger.rb +47 -68
  39. data/lib/yell/repository.rb +3 -5
  40. data/lib/yell/silencer.rb +30 -14
  41. data/lib/yell/version.rb +1 -4
  42. data/lib/yell.rb +29 -11
  43. data/yell.gemspec +22 -15
  44. metadata +19 -50
  45. data/spec/fixtures/yell.yml +0 -7
  46. data/spec/spec_helper.rb +0 -50
  47. data/spec/threaded/yell_spec.rb +0 -100
  48. data/spec/yell/adapters/base_spec.rb +0 -43
  49. data/spec/yell/adapters/datefile_spec.rb +0 -168
  50. data/spec/yell/adapters/file_spec.rb +0 -75
  51. data/spec/yell/adapters/io_spec.rb +0 -72
  52. data/spec/yell/adapters/streams_spec.rb +0 -26
  53. data/spec/yell/adapters_spec.rb +0 -45
  54. data/spec/yell/configuration_spec.rb +0 -36
  55. data/spec/yell/event_spec.rb +0 -97
  56. data/spec/yell/formatter_spec.rb +0 -136
  57. data/spec/yell/level_spec.rb +0 -200
  58. data/spec/yell/loggable_spec.rb +0 -20
  59. data/spec/yell/logger_spec.rb +0 -263
  60. data/spec/yell/repository_spec.rb +0 -70
  61. data/spec/yell/silencer_spec.rb +0 -49
  62. data/spec/yell_spec.rb +0 -102
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9ecfe3dde614dc7aaa4d58f6617323dfd22aa6b
4
- data.tar.gz: a16b4a0ed5c83a1d722570a7d4e92eb0886856ff
3
+ metadata.gz: 9aae01c5c4e5cf4acfc08f3579266c32410184de
4
+ data.tar.gz: 54dc91a4941d54b7f4175ef2712145f668d48596
5
5
  SHA512:
6
- metadata.gz: dbfd34addbe7e79d5a0264f927f64bd9808a1cc09dbe4e56fda1b09677e66cdcb20c527e86a75cbb0954bc9f9f3cfd4ef5b67b052c1d19527888fe856d43f116
7
- data.tar.gz: 438d38c8cdd63f08eb32d991eacb04eb1aa1b3bd7020a017d44b954d80bc268c69132ddcc36bdd967c809a57804abfe14656d90912ab2833d878808302e936aa
6
+ metadata.gz: 8626bd806d18be33a32b60ca0c67be823592a75be9fa8c2f98ced0fa2b01e9af4efc959c120753a4eb68a15181ed7ba9748476c96601a3ad53f718c6b6b353af
7
+ data.tar.gz: 70e688475cadc7ea3d7a6add37a11a70f3214056e4d377a70c447c01824a94bb29ab23a782dbc145ce4dd3e555719bf9bf27ea4a451d2caec223be5d269eb7b2
data/.gitignore CHANGED
@@ -2,12 +2,16 @@ pkg/*
2
2
  *.gem
3
3
  .bundle
4
4
  .idea
5
-
5
+ .vscode
6
+ vendor/
6
7
  # bundler
7
- Gemfile.lock
8
+ Gemfile.*lock
8
9
 
9
10
  # vim
10
11
  *.swp
11
12
 
12
13
  # coverage
13
14
  /coverage
15
+
16
+ # rspec
17
+ /spec/examples/txt
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml CHANGED
@@ -1,17 +1,20 @@
1
1
  language: ruby
2
+ before_install: gem install bundler
3
+ script: "bundle exec rspec"
2
4
 
3
- script: "rspec"
4
-
5
- rvm:
6
- - 1.8.7
7
- - 1.9.3
8
- - 2.0.0
9
- - jruby-18mode
10
- - jruby-19mode
11
- - rbx-18mode
12
- - rbx-19mode
13
- - ree
5
+ matrix:
6
+ include:
7
+ - rvm: ruby-head
8
+ - rvm: 2.6
9
+ - rvm: 2.5
10
+ - rvm: 2.4
11
+ - rvm: 2.3
12
+ - rvm: jruby-9.1
13
+ - rvm: jruby-9.2
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ - rvm: jruby-head
14
17
 
15
18
  notifications:
16
- email:
17
- - me@rudionrails.com
19
+ on_success: change
20
+ on_failure: change
data/Gemfile CHANGED
@@ -1,17 +1,24 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in yell.gemspec
4
6
  gemspec
5
7
 
6
8
  group :development, :test do
7
- gem "rake"
9
+ gem 'rake'
8
10
 
9
- gem 'rspec-core'
11
+ gem 'rspec-core', '~> 3'
10
12
  gem 'rspec-expectations'
11
- gem "rr"
12
- gem "timecop"
13
+ gem 'rspec-its'
14
+ gem 'rspec-mocks'
13
15
 
14
- gem 'simplecov', :require => false, :platform => :ruby_20
15
- gem 'coveralls', :require => false, :platform => :ruby_20
16
- end
16
+ gem 'byebug', platform: :mri
17
+ gem 'timecop'
17
18
 
19
+ gem 'activesupport', '~> 5'
20
+
21
+ gem 'coveralls', require: false
22
+ gem 'rubocop', require: false
23
+ gem 'simplecov', require: false
24
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2013 Rudolf Schmidt
1
+ Copyright (c) 2011-current Rudolf Schmidt
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,9 +1,12 @@
1
- # Yell [![Gem Version](https://badge.fury.io/rb/yell.png)](http://badge.fury.io/rb/yell) [![Build Status](https://travis-ci.org/rudionrails/yell.png?branch=master)](https://travis-ci.org/rudionrails/yell) [![Code Climate](https://codeclimate.com/github/rudionrails/yell.png)](https://codeclimate.com/github/rudionrails/yell) [![Coverage Status](https://coveralls.io/repos/rudionrails/yell/badge.png?branch=master)](https://coveralls.io/r/rudionrails/yell)
1
+ # Yell [![Gem Version](https://badge.fury.io/rb/yell.svg)](http://badge.fury.io/rb/yell) [![Build Status](https://travis-ci.org/rudionrails/yell.svg?branch=master)](https://travis-ci.org/rudionrails/yell) [![Code Climate](https://codeclimate.com/github/rudionrails/yell.svg)](https://codeclimate.com/github/rudionrails/yell) [![Coverage Status](https://coveralls.io/repos/rudionrails/yell/badge.svg?branch=master)](https://coveralls.io/r/rudionrails/yell)
2
2
 
3
3
 
4
4
  **Yell - Your Extensible Logging Library** is a comprehensive logging replacement for Ruby.
5
5
 
6
- Yell works and is tested with ruby 1.8.7, 1.9.x, 2.0.0, jruby 1.8 and 1.9 mode, rubinius 1.8 and 1.9 as well as ree.
6
+ Yell works and its test suite currently runs on:
7
+
8
+ - ruby-head, 2.3.1, 2.2.5, 2.2.2, 2.1.0, 2.0.0
9
+ - jruby-head, jruby-9.1.0.0, jruby-9.0.0.0
7
10
 
8
11
  If you want to conveniently use Yell with Rails, then head over to [yell-rails](https://github.com/rudionrails/yell-rails). You'll find all the documentation in this repository, though.
9
12
 
@@ -189,6 +192,8 @@ logger.debug 'Started GET "/assets/logo.png" for 127.0.0.1 at 2013-06-20 10:18:3
189
192
  logger.debug 'Served asset /logo.png - 304 Not Modified (0ms)'
190
193
  ```
191
194
 
195
+ ### Alter log messages with modifiers
196
+
192
197
 
193
198
  ## Further Readings
194
199
 
@@ -201,7 +206,9 @@ logger.debug 'Served asset /logo.png - 304 Not Modified (0ms)'
201
206
 
202
207
  ### Additional Adapters
203
208
  [Syslog](https://github.com/rudionrails/yell/wiki/additional-adapters-syslog)
209
+ [syslog-sd](https://github.com/raymond-wells/yell-adapters-syslogsd)
204
210
  [Graylog2 (GELF)](https://github.com/rudionrails/yell/wiki/additional-adapters-gelf)
211
+ [Fluentd](https://github.com/red5studios/yell-adapters-fluentd)
205
212
 
206
213
 
207
214
  ### Development
@@ -212,5 +219,5 @@ You can find further examples and additional adapters in the [wiki](https://gith
212
219
  or have a look into the examples folder.
213
220
 
214
221
 
215
- Copyright © 2011-2013 Rudolf Schmidt, released under the MIT license
222
+ Copyright © 2011-current Rudolf Schmidt, released under the MIT license
216
223
 
data/Rakefile CHANGED
@@ -1,6 +1,4 @@
1
- $LOAD_PATH.unshift( 'lib' )
2
- require 'bundler'
3
-
1
+ require 'bundler/gem_tasks'
4
2
 
5
3
  # Run stuff in the examples folder
6
4
  desc "Run examples"
@@ -7,7 +7,7 @@ puts <<-EOS
7
7
  # Like many other logging libraries, Yell allows you to define from which level
8
8
  # onwards you want to write your log message.
9
9
 
10
- logger = Yell.new STDOUT, :level => :info
10
+ logger = Yell.new STDOUT, level: :info
11
11
 
12
12
  logger.debug "This is a :debug message"
13
13
  #=> nil
@@ -19,7 +19,7 @@ logger.info "This is a :info message"
19
19
  EOS
20
20
 
21
21
  puts "=== actual example ==="
22
- logger = Yell.new STDOUT, :level => :info
22
+ logger = Yell.new STDOUT, level: :info
23
23
 
24
24
  logger.debug "This is a :debug message"
25
25
  logger.info "This is a :info message"
@@ -7,10 +7,11 @@ puts <<-EOS
7
7
  # The Yell::Level parser allows you to exactly specify on which levels to log,
8
8
  # ignoring all the others. For instance: If we want to only log at the :debug
9
9
  # and :warn levels we simply providing an array:
10
+ # * %i[] is a built-in for an array of symbols
10
11
 
11
- logger = Yell.new STDOUT, :level => [:debug, :warn]
12
+ logger = Yell.new STDOUT, level: %i[debug warn]
12
13
 
13
- [:debug, :info, :warn, :error, :fatal].each do |level|
14
+ %i[debug info warn error fatal].each do |level|
14
15
  logger.send( level, level )
15
16
  end
16
17
  #=> "2012-02-29T09:30:00+01:00 [DEBUG] 65784 : debug"
@@ -20,9 +21,9 @@ end
20
21
  EOS
21
22
 
22
23
  puts "=== actual example ==="
23
- logger = Yell.new STDOUT, :level => [:debug, :warn]
24
+ logger = Yell.new STDOUT, level: %i[debug warn]
24
25
 
25
- [:debug, :info, :warn, :error, :fatal].each do |level|
26
+ %i[debug info warn error fatal].each do |level|
26
27
  logger.send( level, level )
27
28
  end
28
29
 
@@ -6,10 +6,12 @@ puts <<-EOS
6
6
 
7
7
  # Additionally to writing only on specific levels, you may pass a range to
8
8
  # the :level option:
9
+ # * %i[] is a built-in for an array of symbols
9
10
 
10
- logger = Yell.new STDOUT, :level => (:debug..:warn)
11
11
 
12
- [:debug, :info, :warn, :error, :fatal].each do |level|
12
+ logger = Yell.new STDOUT, level: (:debug..:warn)
13
+
14
+ %i[debug info warn error fatal].each do |level|
13
15
  logger.send( level, level )
14
16
  end
15
17
  #=> "2012-02-29T09:30:00+01:00 [DEBUG] 65784 : debug"
@@ -19,10 +21,10 @@ end
19
21
 
20
22
  EOS
21
23
 
22
- puts "=== actuale example ==="
23
- logger = Yell.new STDOUT, :level => (:debug..:warn)
24
+ puts "=== actual example ==="
25
+ logger = Yell.new STDOUT, level: (:debug..:warn)
24
26
 
25
- [:debug, :info, :warn, :error, :fatal].each do |level|
27
+ %i[debug info warn error fatal].each do |level|
26
28
  logger.send( level, level )
27
29
  end
28
30
 
@@ -7,7 +7,7 @@ puts <<-EOS
7
7
  # The default formatting string looks like: %d [%5L] %p : %m and is used when
8
8
  # nothing else is defined.
9
9
 
10
- logger = Yell.new STDOUT, :format => Yell::DefaultFormat
10
+ logger = Yell.new STDOUT, format: Yell::DefaultFormat
11
11
  logger.info "Hello World!"
12
12
  #=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : Hello World!"
13
13
  # ^ ^ ^ ^
@@ -16,7 +16,7 @@ logger.info "Hello World!"
16
16
 
17
17
  EOS
18
18
 
19
- puts "=== actuale example ==="
20
- logger = Yell.new STDOUT, :format => Yell::DefaultFormat
19
+ puts "=== actual example ==="
20
+ logger = Yell.new STDOUT, format: Yell::DefaultFormat
21
21
  logger.info "Hello World!"
22
22
 
@@ -6,7 +6,7 @@ puts <<-EOS
6
6
 
7
7
  # The basic formating string looks like: %l, %d: %m.
8
8
 
9
- logger = Yell.new STDOUT, :format => Yell::BasicFormat
9
+ logger = Yell.new STDOUT, format: Yell::BasicFormat
10
10
  logger.info "Hello World!"
11
11
  #=> "I, 2012-02-29T09:30:00+01:00 : Hello World!"
12
12
  # ^ ^ ^
@@ -16,7 +16,7 @@ logger.info "Hello World!"
16
16
 
17
17
  EOS
18
18
 
19
- puts "=== actuale example ==="
20
- logger = Yell.new STDOUT, :format => Yell::BasicFormat
19
+ puts "=== actual example ==="
20
+ logger = Yell.new STDOUT, format: Yell::BasicFormat
21
21
  logger.info "Hello World!"
22
22
 
@@ -6,7 +6,7 @@ puts <<-EOS
6
6
 
7
7
  # The extended formatting string looks like: %d [%5L] %p %h : %m.
8
8
 
9
- logger = Yell.new STDOUT, :format => Yell::ExtendedFormat
9
+ logger = Yell.new STDOUT, format: Yell::ExtendedFormat
10
10
  logger.info "Hello World!"
11
11
  #=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 localhost : Hello World!"
12
12
  # ^ ^ ^ ^ ^
@@ -15,7 +15,7 @@ logger.info "Hello World!"
15
15
 
16
16
  EOS
17
17
 
18
- puts "=== actuale example ==="
19
- logger = Yell.new STDOUT, :format => Yell::ExtendedFormat
18
+ puts "=== actual example ==="
19
+ logger = Yell.new STDOUT, format: Yell::ExtendedFormat
20
20
  logger.info "Hello World!"
21
21
 
@@ -6,7 +6,7 @@ puts <<-EOS
6
6
 
7
7
  # The extended formatting string looks like: %d [%5L] %p %h : %m.
8
8
 
9
- logger = Yell.new STDOUT, :format => "[%f:%n in `%M'] %m"
9
+ logger = Yell.new STDOUT, format: "[%f:%n in `%M'] %m", trace: true
10
10
  logger.info "Hello World!"
11
11
  #=> [003.4-formatting-on-your-own.rb:20 in `<main>'] Hello World!
12
12
  # ^ ^ ^ ^
@@ -15,7 +15,7 @@ logger.info "Hello World!"
15
15
 
16
16
  EOS
17
17
 
18
- puts "=== actuale example ==="
19
- logger = Yell.new STDOUT, :format => "[%f:%n in `%M'] %m"
18
+ puts "=== actual example ==="
19
+ logger = Yell.new STDOUT, format: "[%f:%n in `%M'] %m", trace: true
20
20
  logger.info "Hello World!"
21
21
 
@@ -6,7 +6,7 @@ puts <<-EOS
6
6
 
7
7
  You may colorize the log output on your io-based loggers loke so:
8
8
 
9
- logger = Yell.new STDOUT, :colors => true
9
+ logger = Yell.new STDOUT, colors: true
10
10
 
11
11
  Yell::Severities.each do |level|
12
12
  logger.send level.downcase, level
@@ -14,8 +14,8 @@ end
14
14
 
15
15
  EOS
16
16
 
17
- puts "=== actuale example ==="
18
- logger = Yell.new STDOUT, :colors => true
17
+ puts "=== actual example ==="
18
+ logger = Yell.new STDOUT, colors: true
19
19
 
20
20
  Yell::Severities.each do |level|
21
21
  logger.send level.downcase, level
@@ -7,7 +7,7 @@ puts <<-EOS
7
7
  # You can add a logger to the global repository.
8
8
  #
9
9
  # create a logger named 'mylog' that logs to stdout
10
- Yell.new :stdout, :name => 'mylog'
10
+ Yell.new :stdout, name: 'mylog'
11
11
 
12
12
  # Later in the code, you can get your logger back
13
13
  Yell['mylog'].info "Hello World!"
@@ -15,7 +15,7 @@ Yell['mylog'].info "Hello World!"
15
15
 
16
16
  EOS
17
17
 
18
- puts "=== actuale example ==="
19
- Yell.new :stdout, :name => 'mylog'
18
+ puts "=== actual example ==="
19
+ Yell.new :stdout, name: 'mylog'
20
20
  Yell['mylog'].info "Hello World!"
21
21
 
@@ -10,7 +10,7 @@ puts <<-EOS
10
10
  # can use it, though, you will need to define a logger providing the :name of
11
11
  # your class.
12
12
 
13
- Yell.new :stdout, :name => 'Foo'
13
+ Yell.new :stdout, name: 'Foo'
14
14
 
15
15
  # Define the class
16
16
  class Foo
@@ -26,7 +26,7 @@ EOS
26
26
 
27
27
  puts "=== actual example ==="
28
28
 
29
- Yell.new :stdout, :name => 'Foo'
29
+ Yell.new :stdout, name: 'Foo'
30
30
 
31
31
  class Foo
32
32
  include Yell::Loggable
@@ -10,7 +10,7 @@ puts <<-EOS
10
10
  # can use it, though, you will need to define a logger providing the :name of
11
11
  # your class.
12
12
 
13
- Yell.new :stdout, :name => 'Foo'
13
+ Yell.new :stdout, name: 'Foo'
14
14
 
15
15
  # Define the class
16
16
  class Foo
@@ -28,7 +28,7 @@ EOS
28
28
 
29
29
  puts "=== actual example ==="
30
30
 
31
- Yell.new :stdout, :name => 'Foo'
31
+ Yell.new :stdout, name: 'Foo'
32
32
 
33
33
  class Foo
34
34
  include Yell::Loggable
@@ -0,0 +1,17 @@
1
+ require 'logger'
2
+
3
+ class Logger
4
+
5
+ def level_with_yell=( level )
6
+ self.level_without_yell= level.is_a?(Yell::Level) ? Integer(level) : level
7
+ end
8
+ alias_method :level_without_yell=, :level=
9
+ alias_method :level=, :level_with_yell=
10
+
11
+ def add_with_yell( severity, message = nil, progname = nil, &block )
12
+ add_without_yell(Integer(severity), message, progname, &block)
13
+ end
14
+ alias_method :add_without_yell, :add
15
+ alias_method :add, :add_with_yell
16
+
17
+ end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'monitor'
4
2
 
5
3
  module Yell #:nodoc:
@@ -25,7 +23,7 @@ module Yell #:nodoc:
25
23
  # end
26
24
  #
27
25
  # write do |event|
28
- # message = format.format(event)
26
+ # message = format.call(event)
29
27
  #
30
28
  # STDOUT.puts message
31
29
  # end
@@ -52,7 +50,7 @@ module Yell #:nodoc:
52
50
  # @file_handle = File.new( '/dev/null', 'w' )
53
51
  # end
54
52
  def setup( &block )
55
- compile!( :setup!, &block )
53
+ compile!(:setup!, &block)
56
54
  end
57
55
 
58
56
  # Define your write method with this helper.
@@ -62,7 +60,7 @@ module Yell #:nodoc:
62
60
  # @file_handle.puts event.message
63
61
  # end
64
62
  def write( &block )
65
- compile!( :write!, &block )
63
+ compile!(:write!, &block)
66
64
  end
67
65
 
68
66
  # Define your open method with this helper.
@@ -72,7 +70,7 @@ module Yell #:nodoc:
72
70
  # @stream = ::File.open( 'test.log', ::File::WRONLY|::File::APPEND|::File::CREAT )
73
71
  # end
74
72
  def open( &block )
75
- compile!( :open!, &block )
73
+ compile!(:open!, &block)
76
74
  end
77
75
 
78
76
  # Define your close method with this helper.
@@ -82,7 +80,7 @@ module Yell #:nodoc:
82
80
  # @stream.close
83
81
  # end
84
82
  def close( &block )
85
- compile!( :close!, &block )
83
+ compile!(:close!, &block)
86
84
  end
87
85
 
88
86
 
@@ -106,24 +104,24 @@ module Yell #:nodoc:
106
104
  m = instance_method( name )
107
105
 
108
106
  # Create a new method with leading underscore
109
- define_method( "_#{name}", &block )
110
- _m = instance_method( "_#{name}" )
111
- remove_method( "_#{name}" )
107
+ define_method("_#{name}", &block)
108
+ _m = instance_method("_#{name}")
109
+ remove_method("_#{name}")
112
110
 
113
111
  # Define instance method
114
- define!( name, _m, m, &block )
112
+ define!(name, _m, m, &block)
115
113
  end
116
114
 
117
115
  # Define instance method by given name and call the unbound
118
116
  # methods in order with provided block.
119
117
  def define!( name, _m, m, &block )
120
118
  if block.arity == 0
121
- define_method( name ) do
119
+ define_method(name) do
122
120
  _m.bind(self).call
123
121
  m.bind(self).call
124
122
  end
125
123
  else
126
- define_method( name ) do |*args|
124
+ define_method(name) do |*args|
127
125
  _m.bind(self).call(*args)
128
126
  m.bind(self).call(*args)
129
127
  end
@@ -155,7 +153,7 @@ module Yell #:nodoc:
155
153
  # make sure the adapter is closed and re-raise the exception
156
154
  synchronize { close }
157
155
 
158
- raise( e )
156
+ raise(e)
159
157
  end
160
158
 
161
159
  # Close the adapter (stream, connection, etc).
@@ -172,18 +170,15 @@ module Yell #:nodoc:
172
170
  "#<#{self.class.name} #{inspection * ', '}>"
173
171
  end
174
172
 
175
- private
176
173
 
177
- # def reset!
178
- # super()
179
- # end
174
+ private
180
175
 
181
176
  # Setup the adapter instance.
182
177
  #
183
178
  # Adapter classes should provide their own implementation
184
179
  # of this method (if applicable).
185
180
  def setup!( options )
186
- self.level = options[:level]
181
+ self.level = Yell.__fetch__(options, :level)
187
182
  end
188
183
 
189
184
  # Perform the actual write.
@@ -213,18 +208,18 @@ module Yell #:nodoc:
213
208
  # Determine whether to write at the given severity.
214
209
  #
215
210
  # @example
216
- # write? Yell::Event.new( 'INFO', 'Hwllo Wold!' )
211
+ # write? Yell::Event.new( 'INFO', 'Hello Wold!' )
217
212
  #
218
213
  # @param [Yell::Event] event The log event
219
214
  #
220
215
  # @return [Boolean] true or false
221
216
  def write?( event )
222
- @level.nil? || @level.at?( event.level )
217
+ level.nil? || level.at?(event.level)
223
218
  end
224
219
 
225
220
  # Get an array of inspected attributes for the adapter.
226
221
  def inspectables
227
- [ :level ]
222
+ [:level]
228
223
  end
229
224
 
230
225
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module Yell #:nodoc:
4
2
  module Adapters #:nodoc:
5
3
 
@@ -54,16 +52,17 @@ module Yell #:nodoc:
54
52
 
55
53
  # @overload setup!( options )
56
54
  def setup!( options )
57
- @date, @date_strftime = nil, nil # default; do not override --R
58
-
59
- self.header = options.fetch(:header, true)
60
- self.date_pattern = options.fetch(:date_pattern, DefaultDatePattern)
61
- self.keep = options.fetch(:keep, false)
62
- self.symlink = options.fetch(:symlink, true)
55
+ self.header = Yell.__fetch__(options, :header, default: true)
56
+ self.date_pattern = Yell.__fetch__(options, :date_pattern, default: DefaultDatePattern)
57
+ self.keep = Yell.__fetch__(options, :keep, default: false)
58
+ self.symlink = Yell.__fetch__(options, :symlink, default: true)
63
59
 
64
- @original_filename = ::File.expand_path options.fetch(:filename, default_filename)
60
+ @original_filename = ::File.expand_path(Yell.__fetch__(options, :filename, default: default_filename))
65
61
  options[:filename] = @original_filename
66
62
 
63
+ @date = Time.now
64
+ @date_strftime = @date.strftime(date_pattern)
65
+
67
66
  super
68
67
  end
69
68
 
@@ -85,7 +84,7 @@ module Yell #:nodoc:
85
84
 
86
85
  # @overload close!
87
86
  def close!
88
- @filename = filename_for( @date )
87
+ @filename = filename_for(@date)
89
88
 
90
89
  super
91
90
  end
@@ -116,7 +115,7 @@ module Yell #:nodoc:
116
115
  # it makes the best guess by checking the last access time (which may result
117
116
  # in false cleanups).
118
117
  def cleanup!
119
- files = Dir[ @original_filename.sub( /(\.\w+)?$/, ".*\\1" ) ].sort.select do |file|
118
+ files = Dir[ @original_filename.sub(/(\.\w+)?$/, ".*\\1") ].sort.select do |file|
120
119
  _, pattern = header_from(file)
121
120
 
122
121
  # Select if the date pattern is nil (no header info available within the file) or
@@ -139,14 +138,16 @@ module Yell #:nodoc:
139
138
  # do nothing, because symlink is already correct
140
139
  return if ::File.symlink?(@original_filename) && ::File.readlink(@original_filename) == @filename
141
140
 
142
- ::File.unlink( @original_filename ) if ::File.exist?( @original_filename )
143
- ::File.symlink( @filename, @original_filename )
141
+ ::File.unlink(@original_filename) if ::File.exist?(@original_filename) || ::File.symlink?(@original_filename)
142
+ ::File.symlink(@filename, @original_filename)
144
143
  end
145
144
 
146
145
  # Symlink the original filename?
147
146
  #
148
147
  # @return [Boolean] true or false
149
- def symlink?; !!symlink; end
148
+ def symlink?
149
+ !!symlink
150
+ end
150
151
 
151
152
  # Write the header information into the file
152
153
  def header!
@@ -156,36 +157,36 @@ module Yell #:nodoc:
156
157
  # Write header into the file?
157
158
  #
158
159
  # @return [Boolean] true or false
159
- def header?; !!header; end
160
+ def header?
161
+ !!header
162
+ end
160
163
 
161
164
  # Sets the filename with the `:date_pattern` appended to it.
162
165
  def filename_for( date )
163
- @original_filename.sub( /(\.\w+)?$/, ".#{date.strftime(date_pattern)}\\1" )
166
+ @original_filename.sub(/(\.\w+)?$/, ".#{date.strftime(date_pattern)}\\1")
164
167
  end
165
168
 
166
169
  # Fetch the header form the file
167
170
  def header_from( file )
168
- if m = ::File.open( file, &:readline ).match( HeaderRegexp )
171
+ if m = ::File.open(file, &:readline).match(HeaderRegexp)
169
172
  # in case there is a Header present, we can just read from it
170
- [ Time.at( m[2].to_f ), m[3] ]
173
+ [ Time.at(m[2].to_f), m[3] ]
171
174
  else
172
175
  # In case there is no header: we need to take a good guess
173
176
  #
174
177
  # Since the pattern can not be determined, we will just return the Posix ctime.
175
178
  # That is NOT the creatint time, so the value will potentially be wrong!
176
- [ ::File.ctime(file), nil ]
179
+ [::File.ctime(file), nil]
177
180
  end
178
181
  end
179
182
 
180
183
  # @overload inspectables
181
184
  def inspectables
182
- super.concat [:date_pattern, :header, :keep, :symlink ]
185
+ super.concat %i[date_pattern header keep symlink]
183
186
  end
184
187
 
185
188
  end
186
189
 
187
- register( :datefile, Yell::Adapters::Datefile )
188
-
189
190
  end
190
191
  end
191
192