loggability 0.3.0 → 0.4.0

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.
data.tar.gz.sig CHANGED
@@ -1,2 +1 @@
1
- ���J
2
- ��70�>���B<��ߘ����5�$���ԋ��ry���;����-��""Fa�2��J;u'��p5�8j��W+B7m�ꢹ �X��;� �����Ze�����$[�2��Y�����)h�XD��,� ��T����?'�% H!�"}���$>�c �`�ܾ5��R W�ІE�"�����mDa��n4n�;Ն5�r�o��92��]�u�
3
1
  ��'����5 ��^��64��᷏��Biy��Y�P ���
2
+ ?�R�<��R��?�pmC:�kΊda����$}#eY��}G �����lM+ۋ�|i��� �>!
4
3
  #���.����j����m9��h�e���F1d�d�"�y�u�ƀѰ�����-���5@�+���߱�a��ึ�����C>[��kv:���F�a���6P�/l&٧�GJjl�=�^��ST��
data/ChangeLog CHANGED
@@ -1,9 +1,27 @@
1
+ 2012-05-26 Michael Granger <ged@FaerieMUD.org>
2
+
3
+ * .hgtags:
4
+ Added tag v0.3.0 for changeset 6c526d42bafb
5
+ [581580843d12] [tip]
6
+
7
+ * .hgsigs:
8
+ Added signature for changeset 7b6ef57de872
9
+ [6c526d42bafb] [v0.3.0]
10
+
11
+ * History.rdoc, lib/loggability.rb:
12
+ Bump the minor version, update history.
13
+ [7b6ef57de872]
14
+
15
+ * Manifest.txt, lib/loggability/spechelpers.rb, spec/lib/helpers.rb:
16
+ Add Loggability::SpecHelpers for setting up logging in tests.
17
+ [e9edf26e0c6a]
18
+
1
19
  2012-05-22 Michael Granger <ged@FaerieMUD.org>
2
20
 
3
21
  * lib/loggability/formatter.rb, spec/loggability/formatter_spec.rb,
4
22
  spec/loggability/logger_spec.rb:
5
23
  Downcase the severity before outputting.
6
- [040bb1a5dc84] [tip]
24
+ [040bb1a5dc84] [github/master]
7
25
 
8
26
  2012-05-18 Michael Granger <ged@FaerieMUD.org>
9
27
 
@@ -1,3 +1,14 @@
1
+ == v0.4.0 [2012-05-26] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Add some conversion-convenience code. You can now assign ::Logger
4
+ instances to LogHosts, use ::Logger::Formatter, and construct
5
+ Loggability::Logger instances with any device supported by
6
+ #output_to.
7
+
8
+ Also adds a Loggability::Logger() casting method for easy logger
9
+ creation.
10
+
11
+
1
12
  == v0.3.0 [2012-05-26] Michael Granger <ged@FaerieMUD.org>
2
13
 
3
14
  - Add Loggability::SpecHelpers for setting up logging in tests.
@@ -9,10 +9,10 @@ require 'date'
9
9
  module Loggability
10
10
 
11
11
  # Package version constant
12
- VERSION = '0.3.0'
12
+ VERSION = '0.4.0'
13
13
 
14
14
  # VCS revision
15
- REVISION = %q$Revision: 7b6ef57de872 $
15
+ REVISION = %q$Revision: 2615ed217d34 $
16
16
 
17
17
  # The key for the global logger (Loggability's own logger)
18
18
  GLOBAL_KEY = :__global__
@@ -61,6 +61,15 @@ module Loggability
61
61
  end
62
62
 
63
63
 
64
+ ### Cast the given +device+ to a Loggability::Logger, if possible, and return it. If
65
+ ### it can't be converted, raises a ArgumentError.
66
+ def self::Logger( device )
67
+ return device if device.is_a?( Loggability::Logger )
68
+ return Loggability::Logger.from_std_logger( device ) if device.is_a?( ::Logger )
69
+ return Loggability::Logger.new( device )
70
+ end
71
+
72
+
64
73
  ### Register the specified +host+ as a log host. It should already have been extended
65
74
  ### with LogHostMethods.
66
75
  def self::register_loghost( host )
@@ -188,13 +197,20 @@ module Loggability
188
197
  attr_accessor :default_logger
189
198
 
190
199
  # The logger that's currently in effect
191
- attr_accessor :logger
200
+ attr_reader :logger
192
201
  alias_method :log, :logger
193
- alias_method :log=, :logger=
194
202
 
195
203
  # The key associated with the logger for this host
196
204
  attr_accessor :log_host_key
197
205
 
206
+
207
+ ### Set the logger associated with the LogHost to +newlogger+. If +newlogger+ isn't a
208
+ ### Loggability::Logger, it will be converted to one.
209
+ def logger=( newlogger )
210
+ @logger = Loggability::Logger( newlogger )
211
+ end
212
+ alias_method :log=, :logger=
213
+
198
214
  end # module LogHost
199
215
 
200
216
 
@@ -125,10 +125,31 @@ class Loggability::Logger < ::Logger
125
125
  end # class ObjectNameProxy
126
126
 
127
127
 
128
+ ### Return an equivalent Loggability::Logger object for the given +logger+.
129
+ def self::from_std_logger( logger )
130
+ device = logger.instance_variable_get( :@logdev ) or
131
+ raise ArgumentError, "%p doesn't appear to be a Logger (no @logdev)" % [ logger ]
132
+
133
+ newlogger = self.new( device.dev )
134
+
135
+ newlogger.level = logger.level
136
+ newlogger.formatter = logger.formatter
137
+
138
+ return newlogger
139
+ end
140
+
141
+
142
+ #################################################################
143
+ ### I N S T A N C E M E T H O D S
144
+ #################################################################
145
+
128
146
  ### Create a new Logger wrapper that will output to the specified +logdev+.
129
147
  def initialize( logdev=DEFAULT_DEVICE, *args )
130
- super
148
+ super( nil )
149
+
131
150
  self.level = if $DEBUG then :debug else :warn end
151
+ self.output_to( logdev, *args )
152
+
132
153
  @default_formatter = Loggability::Formatter.create( :default )
133
154
  end
134
155
 
@@ -189,7 +210,7 @@ class Loggability::Logger < ::Logger
189
210
  ### set up logging to any object that responds to #<<.
190
211
  def output_to( target, *args )
191
212
  if target.respond_to?( :write ) || target.is_a?( String )
192
- opts = { :shift_age => args.shift, :shift_size => args.shift }
213
+ opts = { :shift_age => args.shift || 0, :shift_size => args.shift || 1048576 }
193
214
  self.logdev = Logger::LogDevice.new( target, opts )
194
215
  elsif target.respond_to?( :<< )
195
216
  self.logdev = AppendingLogDevice.new( target )
@@ -35,6 +35,17 @@ describe Loggability::Logger do
35
35
  @logger.inspect.should =~ /severity: \S+ formatter: \S+ outputting to: \S+/
36
36
  end
37
37
 
38
+
39
+ it "provides an upgrade constructor for regular Logger objects" do
40
+ logger = ::Logger.new( $stderr )
41
+ newlogger = described_class.from_std_logger( logger )
42
+ newlogger.should be_a( Loggability::Logger )
43
+ newlogger.logdev.dev.should be( logger.instance_variable_get(:@logdev).dev )
44
+ Loggability::LOG_LEVELS[ newlogger.level ].should == logger.level
45
+ newlogger.formatter.should be_a( Loggability::Formatter::Default )
46
+ end
47
+
48
+
38
49
  describe "severity level API" do
39
50
 
40
51
  it "defaults to :warn level" do
@@ -128,6 +139,15 @@ describe Loggability::Logger do
128
139
  @logger.formatter.should be_a( Loggability::Formatter::HTML )
129
140
  end
130
141
 
142
+ it "supports formatting with ::Logger::Formatter, too" do
143
+ output = []
144
+ @logger.output_to( output )
145
+ @logger.level = :debug
146
+ @logger.formatter = ::Logger::Formatter.new
147
+ @logger.debug "This should work."
148
+ output.first.should =~ /D, \[\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d+ #\d+\] DEBUG -- : This should work.\n/
149
+ end
150
+
131
151
  end
132
152
 
133
153
 
@@ -26,6 +26,7 @@ describe Loggability do
26
26
  described_class.log_hosts.should include( Loggability::GLOBAL_KEY => Loggability )
27
27
  end
28
28
 
29
+
29
30
  describe "version methods" do
30
31
  it "returns a version string if asked" do
31
32
  described_class.version_string.should =~ /\w+ [\d.]+/
@@ -84,6 +85,17 @@ describe Loggability do
84
85
  Loggability[ subclass ].should be( origin.logger )
85
86
  end
86
87
 
88
+ it "wraps Logger instances assigned as its logger in a Loggability::Logger" do
89
+ @class.log_as( :testing )
90
+
91
+ logger = ::Logger.new( $stderr )
92
+
93
+ @class.logger = logger
94
+ @class.logger.should be_a( Loggability::Logger )
95
+
96
+ @class.log.debug "This shouldn't raise."
97
+ end
98
+
87
99
  end
88
100
 
89
101
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -36,7 +36,7 @@ cert_chain:
36
36
  YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
37
37
  Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
38
38
  cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
39
- date: 2012-05-26 00:00:00.000000000 Z
39
+ date: 2012-06-07 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pluginfactory
metadata.gz.sig CHANGED
Binary file