lapis 0.2.3 → 0.2.4

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lapis.rb +33 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d04df9ee553d521702522a912b53071aefc8152
4
- data.tar.gz: 70acf1910655be53ccca0d440557b8e51ff1f531
3
+ metadata.gz: 8bb0850e11a2e937e6f7b3fb28cd4f01e525d7c7
4
+ data.tar.gz: 1a7d57ce4c871b8c794ba5d673ca7733d592c8a9
5
5
  SHA512:
6
- metadata.gz: 1ea8cae4ce82f42e8d3eb5f305a898d4488f2b2dbfd2364d05aef59d61c7514f8589aad4deb98b32419ff32c4b518e343703d1486e20ab625fa70640eceb556a
7
- data.tar.gz: f9e9a779c99fc672c96b31023cb53357b714c4f8f8e9ce113048b6f16774707f8fbbe9067358e25eb790b5848f91d4360bdbbfb2eb3ca8a799452aa9edee159e
6
+ metadata.gz: 834af6d35e9aa5243521b805e8b5fbdc08aea51b3f44259f2d52d7e06ca48083d7c6e3762b84ab8d2bf392d8b384c475473b60c5b889fea7cfc8c0f4bf2ea40f
7
+ data.tar.gz: 530f1ea24b6adc23ddbb764b28289bc1af2e2a2908221b6f305d85ab0b8092bb156bf3adee624e113a2a425ec3d2409466804e703c9688f5a8e7a1bd88df105e
data/lib/lapis.rb CHANGED
@@ -1,7 +1,16 @@
1
1
  module Lapis
2
2
 
3
- VERSION = '0.2.3'
3
+ VERSION = '0.2.4'
4
4
 
5
+ # +Lapis::Logger+ is a simple, lightweight logging utility. It is fully
6
+ # customizable; in particular, you can customize the following:
7
+ # * +levels+ -- An array of symbols, which determines the valid levels. See
8
+ # its' documentation for more info.
9
+ # * +formatter+ -- A lambda, used for formatting output. Upon a call to log,
10
+ # this will be called with the severity of the message and the message
11
+ # itself (in that order).
12
+ # * +output_channel+ -- An IO object, representing the destination for all
13
+ # output.
5
14
  class Logger
6
15
 
7
16
  # Special levels that will be sent to +@levels+ as method calls.
@@ -9,15 +18,19 @@ module Lapis
9
18
 
10
19
  # An array of all valid severity levels. Each levels' offset in this array
11
20
  # determines its relative importance.
21
+ # @return [Array<Symbol>]
12
22
  attr_accessor :levels
13
23
 
14
24
  # The minimum severity level required for printing
25
+ # @return [Symbol]
15
26
  attr_reader :level
16
27
 
17
28
  # A lambda, used to format the output
29
+ # @return [Lambda]
18
30
  attr_accessor :formatter
19
31
 
20
32
  # The IO channel to output to
33
+ # @return [IO]
21
34
  attr_reader :output_channel
22
35
 
23
36
  def initialize(out = $stdout, level = :info,
@@ -31,6 +44,10 @@ module Lapis
31
44
  end
32
45
  end
33
46
 
47
+ # A factory method for logging to files. Functions exactly as the regular
48
+ # +new+ method, expect instead of expecting an IO object, it expects the
49
+ # name of a file.
50
+ # @param file [String] the name of the file to log output to
34
51
  def self.open(file, level = :info,
35
52
  levels = [:debug, :info, :warn, :error, :fatal])
36
53
  new(File.open(file, "w"), level, levels)
@@ -46,23 +63,38 @@ module Lapis
46
63
  end
47
64
  end
48
65
 
66
+ # Determine if the specified severity level is important (i.e., will be
67
+ # printed when that level is called).
68
+ # @param severity [Symbol] the severity level to check
69
+ # @return [Boolean] whether the specified severity is important
49
70
  def important?(severity)
50
71
  @levels.index(severity) >= @levels.index(@level) if @levels.index(severity)
51
72
  end
52
73
 
74
+ # Determine if we're logging to a file.
53
75
  def file?
54
76
  @output_channel.is_a? File
55
77
  end
56
78
 
79
+ # Log a message. +severity+ is expected to be the name of a severity level,
80
+ # and +msg+ is a string denoting the message to be logged. If we're logging
81
+ # to a file, the file's buffer will be flushed immediately after logging.
82
+ # @param severity [Symbol] how severe the message is
83
+ # @param msg [String] the message to be logged
84
+ # @return [void]
57
85
  def log(severity, msg)
58
86
  @formatter.call(severity, msg) if important?(severity)
59
87
  output_channel.flush if file?
60
88
  end
89
+
90
+ private
61
91
 
92
+ # @api private
62
93
  def respond_to_missing?(name, include_private = false)
63
94
  @levels.include?(name) || super
64
95
  end
65
96
 
97
+ # @api private
66
98
  def method_missing(name, *args)
67
99
  return super unless @levels.include?(name)
68
100
  if args.length == 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lapis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Citruxy