lapis 1.0.0 → 1.1.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -17
  3. data/lib/lapis.rb +10 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42e36c63db5206c7f4f826119ef5cf93868aa414
4
- data.tar.gz: 6e49dc0ca0f20b9bd81aa2fbbe9c91fbabc1220d
3
+ metadata.gz: 06aee066a6540c2adc57450a61e7a07189358555
4
+ data.tar.gz: b2150a91cc8b8539b7cf048c9b58c3ea9b93b210
5
5
  SHA512:
6
- metadata.gz: b1c5352ecd0c3c1b8c1882b3710c4bf8a46802b64d0fef0c57e9b61c9711aaf24693a4808092066e7613f776278cae10b62b5e78e52dbfa8c06b1fe0a4d15872
7
- data.tar.gz: 851d107472c602dd6af27a3f8290450f35cab7eaae279a9e95298ed37ef9a42c9188a41b4c0de015e6b3ea997af4163f6d149bcde5c9e6f80e5e2f919a8e6523
6
+ metadata.gz: 78a7106706e487a608459d04fd436944bf48ebdf5626f14fe0601e0bf01f3ca4e8f8cf996394bcc1ff78056098e20d21732f37d00dd02240b39d736638100a91
7
+ data.tar.gz: 0cc90d094243dae821e0c60967acbc015a6a43ed16e3d6fbaff7c5a8f1c1e496db9d0495249154c6a954107807b0073f83bed87ed74717fe455ea02fee17ee3d
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Lapis -- A simple, lightweight logging utility
1
+ # Lapis
2
2
 
3
3
  Lapis is a simple, extensible logging utility. It provides the bare minimum
4
4
  needed to function, and lets you do the rest. You can provide your own
@@ -21,50 +21,70 @@ $ gem install lapis
21
21
 
22
22
  ## Usage
23
23
 
24
- The simplest use case is to simply make an instance of `Lapis::Logger` and start
24
+ The simplest use case is to make an instance of `Lapis::Logger` and start
25
25
  using it, which will provide a default formatting function and output to
26
26
  `$stdout`:
27
27
  ```ruby
28
28
  logger = Lapis::Logger.new
29
- logger.info('Hello, world!')
29
+ logger.info('Hello, world!') # => info: Hello, world!
30
30
  ```
31
- This will print `info: Hello, world!`
32
31
 
33
- If you want more customization, everything about the logger is customizable
34
- except for the output channel. For instance, to provide your own formatting
35
- function:
32
+ If you want more customization, everything about the logger is customizable.
33
+ For instance, you can provide your own formatting function by setting the value
34
+ of `formatter`:
36
35
  ```ruby
37
36
  logger = Lapis::Logger.new
38
37
  logger.formatter = lambda do |level, msg|
39
38
  output_channel.puts "[#{level.to_s.upcase}] #{msg}"
40
39
  end
41
40
 
42
- logger.info('Hello, world!')
41
+ logger.info('Hello, world!') # => [INFO] Hello, world!
43
42
  ```
44
- This will print `[INFO] Hello, world!`
45
43
 
46
- If you want, you can also set `levels` to an array of your choice. If you do
47
- this in the constructor, you must also pass in an initial value for `level`:
44
+ You can also customize the severity levels by setting the value of `levels` to
45
+ an array. Levels should be ordered by their relative severity. You can do this
46
+ straight from the constructor, although you will have to pass in the output
47
+ channel explicitly. It is also recommended to set `level` to something sensible
48
+ instead of the default, `:info`:
48
49
  ```ruby
50
+ # Doing everything in the constructor
49
51
  Lapis::Logger.new($stdout, :bar, [:foo, :bar, :baz, :quux])
52
+
53
+ # Setting things explicitly
54
+ logger = Lapis::Logger.new
55
+ logger.levels = [:foo, :bar, :baz, :quux]
56
+ logger.level = :bar
50
57
  ```
51
58
  In the example above, `:foo` is the least important (equivalent to `:debug`),
52
- and `:quux` is the most important (equivalent to `:fatal`). Because the shortcut
53
- methods are magic, you can automagically call each value:
59
+ and `:quux` is the most important (equivalent to `:fatal`). Additionally, you
60
+ can automagically call each value:
54
61
  ```ruby
55
62
  logger = Lapis::Logger.new($stdout, :bar, [:foo, :bar, :baz, :quux])
56
63
  logger.bar('Hello, world!') # => bar: Hello, world!
57
64
  logger.foo('Hello, world!') # => No output
58
65
  ```
59
66
 
60
- Finally, as a convenience, the `open` factory method is provided to easily log
61
- output to files:
67
+ The `Logger` class defines two factory methods, `open` and `dummy`.
68
+
69
+ The `open` factory method is provided to easily log output to files:
62
70
  ```ruby
63
71
  logger = Lapis::Logger.open('foo.log')
64
72
  logger.info('Hello, world!')
65
73
  ```
66
- This is equivalent to using `new`, except output is redirected to the file named
67
- in the constructor.
74
+ This is just shorthand for the following:
75
+ ```ruby
76
+ logger = Lapis::Logger.new(File.open('foo.log'))
77
+ logger.info('Hello, world!')
78
+ ```
79
+
80
+ The `dummy` factory method is provided to create a 'dummy' object which discards
81
+ all output:
82
+ ```ruby
83
+ logger = Lapis::Logger.dummy
84
+ logger.info('Hello, world!') # => does nothing
85
+ ```
86
+ Internally, the `dummy` method simply makes a new instance of `Logger` and sets
87
+ its formatting function to an 'empty' lambda (i.e., a lambda that does nothing).
68
88
 
69
89
  ## Contributing
70
90
 
data/lib/lapis.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Lapis
2
2
 
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
 
5
5
  # +Lapis::Logger+ is a simple, lightweight logging utility. It is fully
6
6
  # customizable; in particular, you can customize the following:
@@ -50,10 +50,19 @@ module Lapis
50
50
  # +new+ method, expect instead of expecting an IO object, it expects the
51
51
  # name of a file.
52
52
  # @param file [String] the name of the file to log output to
53
+ # @return [Lapis::Logger]
53
54
  def self.open(file, level=DEFAULT_LEVEL, levels=DEFAULT_LEVELS)
54
55
  new(File.open(file, "w"), level, levels)
55
56
  end
56
57
 
58
+ # A factory method for getting a dummy instance. Returns a new instance of
59
+ # Logger with an 'empty' lambda as its formatting function.
60
+ def self.dummy
61
+ dummy = new
62
+ dummy.formatter = lambda { |level, msg| }
63
+ dummy
64
+ end
65
+
57
66
  def level=(level)
58
67
  if @levels.include?(level)
59
68
  @level = level
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: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Citruxy