barking_iguana-logging 0.1.2 → 0.1.3

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: fa9f2b9929e5a3f443934df4e561d4da4db7814b
4
- data.tar.gz: d38829452a7f78aa0b391f50f89113f3dfc09384
3
+ metadata.gz: bbe44bdb67fc755a8ed631066868824a12e2a6ed
4
+ data.tar.gz: 37abf2f060647d9dcd122b835ea6251b95fc495d
5
5
  SHA512:
6
- metadata.gz: 327d124bb6ed427016a978e05648fbd8b8570a8218fc97685f2b76b65c53e01562c21d18e36705e671ba1a722978f830ecad127bfb50357b1fcce888c51f7207
7
- data.tar.gz: 559f48f407833598b5a8d767288bbe29798050e0eaf016b2412ab260e1b9e85a78a9fee627f75025ce934277583981a97f5b6dd2919b7396039f4c647af7dfa0
6
+ metadata.gz: e594d414ddf688c93417f937808d8520bd4759de4ca8a07fe590e9c48ba3aec94f954275fc359fc8f5103108ba182eb304486a599307776a99f31347eb6392f0
7
+ data.tar.gz: c3dcfa0b04bddc5d6458cf6446b58d66f46011659f9e838e3e2744d3a9be84b7aa51c8b965165a83e542cf4f1521c1f13f31645d212b866c25391c61ff5bd80a
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "rake", "~> 10.0"
31
31
  spec.add_development_dependency "rspec", "~> 3.0"
32
32
  spec.add_dependency "barking_iguana-otk"
33
+ spec.add_dependency "term-ansicolor"
33
34
  end
@@ -0,0 +1,22 @@
1
+ require 'barking_iguana/logging'
2
+
3
+ class Example
4
+ include BarkingIguana::Logging::Helper
5
+
6
+ def initialize
7
+ @i = 0
8
+ end
9
+
10
+ def run
11
+ @i += 1
12
+ logger.info { "Testing #{@i.to_s.rjust(3, '0')}" }
13
+ end
14
+ end
15
+
16
+ @examples = (1..10).to_a.map do
17
+ Example.new
18
+ end
19
+
20
+ 100.times do
21
+ @examples.sort_by{rand}.each &:run
22
+ end
@@ -2,12 +2,14 @@ require "barking_iguana/otk/defaults"
2
2
  require "barking_iguana/logging/version"
3
3
  require "barking_iguana/logging/helper"
4
4
  require "barking_iguana/logging/logger"
5
+ require "barking_iguana/logging/output"
6
+ require "term/ansicolor"
5
7
 
6
8
  module BarkingIguana
7
9
  module Logging
8
10
  include Otk::Defaults
9
11
  defaults default_level: Logger::INFO,
10
- default_target: $stdout,
12
+ default_target: Output.new($stdout),
11
13
  default_raw_append_threshold: Logger::DEBUG
12
14
 
13
15
  def self.get_logger for_instance
@@ -17,12 +19,19 @@ module BarkingIguana
17
19
  end
18
20
  end
19
21
 
22
+ def self.colours
23
+ %i(red green yellow blue magenta cyan white)
24
+ end
25
+
20
26
  def self.default_formatter for_instance
21
27
  name = for_instance.class.name
22
28
  id = for_instance.object_id
23
29
  label = "#{name}##{id}"
30
+ @logger_index ||= 0
31
+ @logger_index += 1
32
+ colour = colours[@logger_index % colours.size]
24
33
  lambda do |severity, datetime, _progname, message|
25
- "#{datetime.iso8601} #{label} #{severity.ljust(5)} #{message}\n"
34
+ Term::ANSIColor.public_send colour, "#{datetime.iso8601} #{label} #{severity.ljust(5)} #{message}\n"
26
35
  end
27
36
  end
28
37
  class << self; private :default_formatter; end
@@ -0,0 +1,26 @@
1
+ module BarkingIguana
2
+ module Logging
3
+ class Output
4
+ attr_accessor :io
5
+ private :io=, :io
6
+
7
+ def initialize io
8
+ self.io = io
9
+ end
10
+
11
+ def write message
12
+ @bold = !@bold
13
+ output = if @bold
14
+ Term::ANSIColor.bold message
15
+ else
16
+ message
17
+ end
18
+ io.write output
19
+ end
20
+
21
+ def close
22
+ io.close
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module BarkingIguana
2
2
  module Logging
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barking_iguana-logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig R Webster
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: term-ansicolor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description:
70
84
  email:
71
85
  - craig@barkingiguana.com
@@ -84,9 +98,11 @@ files:
84
98
  - barking_iguana-logging.gemspec
85
99
  - bin/console
86
100
  - bin/setup
101
+ - example/example.rb
87
102
  - lib/barking_iguana/logging.rb
88
103
  - lib/barking_iguana/logging/helper.rb
89
104
  - lib/barking_iguana/logging/logger.rb
105
+ - lib/barking_iguana/logging/output.rb
90
106
  - lib/barking_iguana/logging/version.rb
91
107
  homepage: https://github.com/barkingiguana/logging
92
108
  licenses: