footprint-log 0.1.3 → 0.1.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.
- checksums.yaml +4 -4
- data/README.rdoc +2 -2
- data/lib/footprint/log/basic.rb +23 -4
- data/lib/footprint/log/error_file.rb +17 -0
- data/lib/footprint/log/out_file.rb +17 -0
- data/lib/footprint/middleware/logger.rb +77 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37401f9e0d7fde7d558dd7e1c61eac9453d53036
|
4
|
+
data.tar.gz: 43dade513b5c0270bae125ce185fd50938cd73ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18157ff1383339f8c1a22a9d0f087cd0d9edbc5c37aeeae327ad51f0905247f7238773633805e7dac4feccb8bb16c6b87f53a47da25fa7a0522300abaaf23526
|
7
|
+
data.tar.gz: fdd8c67dbd744379188e0621db5f873a3351aebdaaaabe31c6e6b8b0f693ec316a59cb9ba52757d4938d4b4cd3b74f47666e9e8eef427eb5b65d94000e812c15
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Footprint
|
1
|
+
= Footprint
|
2
2
|
Rack Application Logging Tools
|
3
3
|
|
4
4
|
{<img src="https://badge.fury.io/rb/footprint-log.svg" alt="Gem Version" />}[http://badge.fury.io/rb/footprint-log]
|
@@ -66,7 +66,7 @@ In that case we can do something like this:
|
|
66
66
|
end
|
67
67
|
|
68
68
|
|
69
|
-
Let's assume we want to use the following custom Logger class, initialized with log_device as STDOUT and level as
|
69
|
+
Let's assume we want to use the following custom Logger class, initialized with log_device as STDOUT and level as 1 (that is INFO level).
|
70
70
|
|
71
71
|
class MyAwesomeLogger < Logger
|
72
72
|
|
data/lib/footprint/log/basic.rb
CHANGED
@@ -6,12 +6,31 @@ module Footprint
|
|
6
6
|
|
7
7
|
# Class that extends the Ruby Logger.
|
8
8
|
#
|
9
|
-
# Does nothing extra
|
10
|
-
# configuration in the future since other Footprint::Log
|
11
|
-
# classes extend this.
|
9
|
+
# Does nothing extra except setting the default logdev as nil but will be used to add generic
|
10
|
+
# configuration in the future since other Footprint::Log classes extend this.
|
12
11
|
class Basic < Logger
|
13
12
|
|
14
|
-
#
|
13
|
+
#
|
14
|
+
# === Synopsis
|
15
|
+
#
|
16
|
+
# Footprint::Log::Basic.new(name, shift_age = 7, shift_size = 1048576)
|
17
|
+
# Footprint::Log::Basic.new(name, shift_age = 'weekly')
|
18
|
+
#
|
19
|
+
# === Args
|
20
|
+
#
|
21
|
+
# +logdev+::
|
22
|
+
# The log device. This is a filename (String) or IO object (typically
|
23
|
+
# +STDOUT+, +STDERR+, or an open file, defaults to nil).
|
24
|
+
# +shift_age+::
|
25
|
+
# Number of old log files to keep, *or* frequency of rotation (+daily+,
|
26
|
+
# +weekly+ or +monthly+).
|
27
|
+
# +shift_size+::
|
28
|
+
# Maximum logfile size (only applies when +shift_age+ is a number).
|
29
|
+
#
|
30
|
+
# === Description
|
31
|
+
#
|
32
|
+
# Create an instance with logdev as nil.
|
33
|
+
#
|
15
34
|
def initialize logdev = nil, shift_age = 0, shift_size = 1048576
|
16
35
|
super
|
17
36
|
end
|
@@ -11,7 +11,24 @@ module Footprint
|
|
11
11
|
# write in log.
|
12
12
|
class ErrorFile < Basic
|
13
13
|
|
14
|
+
#
|
15
|
+
# === Synopsis
|
16
|
+
#
|
17
|
+
# write 'My dummy error log message'
|
18
|
+
#
|
19
|
+
# === Args
|
20
|
+
#
|
21
|
+
# +message+::
|
22
|
+
# The log message. A String or Exception.
|
23
|
+
#
|
24
|
+
# === Return
|
25
|
+
#
|
26
|
+
# +true+ if successful, +false+ otherwise.
|
27
|
+
#
|
28
|
+
# === Description
|
29
|
+
#
|
14
30
|
# Logs the message on error level on logger.
|
31
|
+
#
|
15
32
|
def write(message)
|
16
33
|
error message
|
17
34
|
end
|
@@ -11,7 +11,24 @@ module Footprint
|
|
11
11
|
# write in log.
|
12
12
|
class OutFile < Basic
|
13
13
|
|
14
|
+
#
|
15
|
+
# === Synopsis
|
16
|
+
#
|
17
|
+
# write 'My dummy info log message'
|
18
|
+
#
|
19
|
+
# === Args
|
20
|
+
#
|
21
|
+
# +message+::
|
22
|
+
# The log message. A String or Exception.
|
23
|
+
#
|
24
|
+
# === Return
|
25
|
+
#
|
26
|
+
# +true+ if successful, +false+ otherwise.
|
27
|
+
#
|
28
|
+
# === Description
|
29
|
+
#
|
14
30
|
# Logs the message on info level on logger.
|
31
|
+
#
|
15
32
|
def write(message)
|
16
33
|
info message
|
17
34
|
end
|
@@ -8,19 +8,50 @@ module Footprint
|
|
8
8
|
# the application with loggers, taking advantage of the @env.
|
9
9
|
class Middleware
|
10
10
|
|
11
|
-
#
|
12
|
-
|
13
|
-
attr_accessor :app, :logger
|
11
|
+
# The instance of the Rack +app+ that uses this middleware.
|
12
|
+
attr_accessor :app
|
14
13
|
|
15
|
-
#
|
16
|
-
|
14
|
+
# The instance of the +logger+ used to decorate the Rack application.
|
15
|
+
attr_accessor :logger
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#
|
20
|
+
# === Synopsis
|
21
|
+
#
|
22
|
+
# Basic Middleware usage:
|
23
|
+
#
|
24
|
+
# use Footprint::Middleware
|
25
|
+
#
|
26
|
+
# Advanced Middleware usage:
|
27
|
+
#
|
28
|
+
# use Footprint::Middleware do
|
29
|
+
# set Logger, STDOUT
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# Clazz init:
|
33
|
+
#
|
34
|
+
# Footprint::Middleware.new app # => #<Footprint::Middleware>
|
35
|
+
#
|
36
|
+
# === Args
|
37
|
+
#
|
38
|
+
# +app+::
|
39
|
+
# Rack application instance.
|
40
|
+
# +block+::
|
41
|
+
# Optional block, used to instance_eval (defaults to nil)
|
42
|
+
#
|
43
|
+
# === Description
|
44
|
+
#
|
45
|
+
# Initialize the Middleware with the +app+ that uses this
|
46
|
+
# Middleware and an optional +block+.
|
17
47
|
#
|
18
48
|
# Sets as the default logger a Footprint::Log::Basic on STDOUT.
|
19
49
|
#
|
20
|
-
# Decorate the given app with a new method called logger,
|
50
|
+
# Decorate the given +app+ with a new method called logger,
|
21
51
|
# that will return the instance of the logger from the env.
|
22
52
|
#
|
23
|
-
# If any block is given, a instance_eval is called.
|
53
|
+
# If any +block+ is given, a instance_eval is called.
|
54
|
+
#
|
24
55
|
def initialize(app, &block)
|
25
56
|
|
26
57
|
@app = app
|
@@ -35,19 +66,57 @@ module Footprint
|
|
35
66
|
self.instance_eval &block if block
|
36
67
|
end
|
37
68
|
|
38
|
-
|
69
|
+
#
|
70
|
+
# === Synopsis
|
71
|
+
#
|
72
|
+
# Footprint:Middleware.call env # => env
|
73
|
+
#
|
74
|
+
# === Args
|
75
|
+
#
|
76
|
+
# +env+::
|
77
|
+
# Rack request environment.
|
78
|
+
#
|
79
|
+
# === Return
|
80
|
+
#
|
81
|
+
# +env+ returned always.
|
82
|
+
#
|
83
|
+
# === Description
|
84
|
+
#
|
39
85
|
# The current instance of the logger is set on env[:footprint_logger]
|
40
86
|
# and the app is called further with the enriched env.
|
87
|
+
#
|
41
88
|
def call(env)
|
42
89
|
env[:footprint_logger] = @logger
|
43
90
|
@app.call env
|
44
91
|
end
|
45
92
|
|
93
|
+
#
|
94
|
+
# === Synopsis
|
95
|
+
#
|
96
|
+
# Basic usage:
|
97
|
+
#
|
98
|
+
# Footprint.Middleware.set Logger, STDOUT # => logger
|
99
|
+
#
|
100
|
+
# === Args
|
101
|
+
#
|
102
|
+
# +clazz+::
|
103
|
+
# Any Logger class that has the default Logger methods.
|
104
|
+
#
|
105
|
+
# +args+::
|
106
|
+
# Optional array of arguments passed to the Logger class for initialize (defaults to nil)
|
107
|
+
#
|
108
|
+
# === Return
|
109
|
+
#
|
110
|
+
# +logger+ returned always.
|
111
|
+
#
|
112
|
+
# === Description
|
113
|
+
#
|
46
114
|
# Initialize the current instance of the logger with
|
47
115
|
# a new instance of the class given as parameter.
|
48
116
|
#
|
49
117
|
# The initialization of the class given is done using
|
50
118
|
# the second parameter.
|
119
|
+
#
|
51
120
|
def set clazz, *args
|
52
121
|
@logger = clazz.send(:new, *args)
|
53
122
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: footprint-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puiu Ionut
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gelf
|