itz_logger 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -5
- data/lib/itz_logger/log_file.rb +33 -0
- data/lib/itz_logger/logger.rb +13 -8
- data/lib/itz_logger/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 171611dc617d003a9b4a6a3b92202f0f529e27179cb6329866a1a257cf20e53f
|
4
|
+
data.tar.gz: 73523533ada3dd32512226c4347f33acb74ab433060a5c30b09b1f3bff56fa99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32700bd7cad158abc87c8499015245c2bf8c9ef064091a529a8413192358532951bb89d3f6062d1992617c1504d04d3de91bf6d3afa39c95ab395be5806dfe90
|
7
|
+
data.tar.gz: 756ebd564719e4632c7b922af99829fa49913764ebf6d92ff1ee1422fa489f868fdafe3dbbe8c46249fc20d1b869b0276062f36613a8804365881dbf7d3d0892
|
data/README.md
CHANGED
@@ -1,20 +1,25 @@
|
|
1
1
|
# ItzLogger
|
2
2
|
|
3
|
-
|
3
|
+
ItzLogger is the N+1 log gem. Following the rule, that at least once in a life time every programmer has to write a log gem (or lib or app ...).
|
4
|
+
|
5
|
+
This log gem supports multiple output channels:
|
6
|
+
|
7
|
+
1. log to the terminal (stdout only)
|
8
|
+
2. log to a file (not yet implemented)
|
9
|
+
3. log to a RabbitMQ service (not yet implemented)
|
4
10
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
11
|
|
7
12
|
## Installation
|
8
13
|
|
9
14
|
Add this line to your application's Gemfile:
|
10
15
|
|
11
16
|
```ruby
|
12
|
-
gem 'itz_logger'
|
17
|
+
gem 'itz_logger', '~> 0.2.6'
|
13
18
|
```
|
14
19
|
|
15
20
|
And then execute:
|
16
21
|
|
17
|
-
$ bundle
|
22
|
+
$ bundle install
|
18
23
|
|
19
24
|
Or install it yourself as:
|
20
25
|
|
@@ -22,7 +27,42 @@ Or install it yourself as:
|
|
22
27
|
|
23
28
|
## Usage
|
24
29
|
|
25
|
-
|
30
|
+
The usage is straight forward. Require the gem, create an object, configure it and write logs.
|
31
|
+
|
32
|
+
### Log to the terminal (stdout)
|
33
|
+
|
34
|
+
First things first - install the gem. Take a look in the installation section.
|
35
|
+
|
36
|
+
A simple example:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'itz_logger'
|
40
|
+
|
41
|
+
...
|
42
|
+
|
43
|
+
# you can choose the log_level from from
|
44
|
+
# - :info
|
45
|
+
# - :warn
|
46
|
+
# - :debug
|
47
|
+
# - :verbose
|
48
|
+
log_level = :info
|
49
|
+
|
50
|
+
# you can choose the target from
|
51
|
+
# - :log_terminal
|
52
|
+
log_target = :log_terminal
|
53
|
+
|
54
|
+
# create a logger
|
55
|
+
logger = ItzLogger::Logger.new(log_level, log_target)
|
56
|
+
|
57
|
+
# now go ahead
|
58
|
+
logger.info("foo")
|
59
|
+
|
60
|
+
logger.warn("bar")
|
61
|
+
|
62
|
+
logger.debug("baz")
|
63
|
+
|
64
|
+
logger.verbose("foo bar baz")
|
65
|
+
```
|
26
66
|
|
27
67
|
## Development
|
28
68
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require_relative "./message"
|
3
|
+
require_relative "./formatter"
|
4
|
+
|
5
|
+
module ItzLogger
|
6
|
+
class LogFile
|
7
|
+
|
8
|
+
@log_level = nil
|
9
|
+
|
10
|
+
attr_reader :log_level
|
11
|
+
|
12
|
+
def initialize(
|
13
|
+
log_level = ItzLogger::MessageType::INFO,
|
14
|
+
log_file = "/tmp/logfile.log")
|
15
|
+
|
16
|
+
@log_level = log_level
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(_log_level, _message)
|
20
|
+
puts "not yet implemented"
|
21
|
+
# return nil if !ItzLogger::MessageType.equals(@log_level, log_level)
|
22
|
+
|
23
|
+
# message = ItzLogger::Message.new(message, log_level)
|
24
|
+
# ItzLogger::Formatter.format(message)
|
25
|
+
end
|
26
|
+
|
27
|
+
def log_level=(log_level)
|
28
|
+
if ItzLogger::MessageType::TYPES.include?(log_level)
|
29
|
+
@log_level = log_level
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/itz_logger/logger.rb
CHANGED
@@ -8,14 +8,19 @@ module ItzLogger
|
|
8
8
|
|
9
9
|
@log_strategy = nil
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
def initialize(options = {})
|
12
|
+
|
13
|
+
log_level = options.fetch(:log_level, ItzLogger::MessageType::INFO)
|
14
|
+
log_strategy = options.fetch(:log_strategy, ItzLogger::LogStrategy::LOG_TERMINAL)
|
15
|
+
_log_file = options.fetch(:log_file, "./log/logfile.log")
|
16
|
+
|
17
|
+
@log_strategy =
|
18
|
+
case log_strategy
|
19
|
+
when ItzLogger::LogStrategy::LOG_TERMINAL
|
20
|
+
ItzLogger::LogTerminal.new(log_level)
|
21
|
+
when ItzLogger::LogStrategy::LOG_FILE
|
22
|
+
ItzLogger::LogFile.new(log_level)
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
def write(log_level, message)
|
data/lib/itz_logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itz_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Schaarschmidt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- itz_logger.gemspec
|
73
73
|
- lib/itz_logger.rb
|
74
74
|
- lib/itz_logger/formatter.rb
|
75
|
+
- lib/itz_logger/log_file.rb
|
75
76
|
- lib/itz_logger/log_strategy.rb
|
76
77
|
- lib/itz_logger/log_terminal.rb
|
77
78
|
- lib/itz_logger/logger.rb
|