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.
- checksums.yaml +4 -4
- data/README.md +37 -17
- data/lib/lapis.rb +10 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06aee066a6540c2adc57450a61e7a07189358555
|
4
|
+
data.tar.gz: b2150a91cc8b8539b7cf048c9b58c3ea9b93b210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78a7106706e487a608459d04fd436944bf48ebdf5626f14fe0601e0bf01f3ca4e8f8cf996394bcc1ff78056098e20d21732f37d00dd02240b39d736638100a91
|
7
|
+
data.tar.gz: 0cc90d094243dae821e0c60967acbc015a6a43ed16e3d6fbaff7c5a8f1c1e496db9d0495249154c6a954107807b0073f83bed87ed74717fe455ea02fee17ee3d
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Lapis
|
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
|
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
|
-
|
35
|
-
|
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
|
-
|
47
|
-
|
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`).
|
53
|
-
|
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
|
-
|
61
|
-
|
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
|
67
|
-
|
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.
|
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
|