footprint-log 0.1.1 → 0.1.2
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/lib/footprint.rb +6 -6
- data/lib/footprint/log.rb +9 -0
- data/lib/footprint/log/basic.rb +6 -0
- data/lib/footprint/log/error_file.rb +6 -0
- data/lib/footprint/log/gelf.rb +5 -0
- data/lib/footprint/log/out_file.rb +6 -0
- data/lib/footprint/middleware.rb +9 -0
- data/lib/footprint/middleware/logger.rb +23 -0
- 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: 4848d46a5d4b1bcea985f3421eaca78df8c57ede
|
4
|
+
data.tar.gz: 7feb5f3a3a136ba103ed951709c446e284edee85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54d1c47b19db6adfccdc5fd5395a506221415b5b171efdc3e0dfd597bf9f03ec91d7711235523d8c7fcf6ea2efa7131972eb05b84f0a694f6e829c8004a572b2
|
7
|
+
data.tar.gz: b6b2d6063e95fd804f4935f636512bf83d43a8d1c64bf99f66cf7eb57653044d7fc335eca67ad93369a53b0336b83fa7793ce987d6b9d15151402fb5adcbbb24
|
data/lib/footprint.rb
CHANGED
data/lib/footprint/log.rb
CHANGED
data/lib/footprint/log/basic.rb
CHANGED
@@ -4,8 +4,14 @@ module Footprint
|
|
4
4
|
|
5
5
|
module Log
|
6
6
|
|
7
|
+
# Class that extends the Ruby Logger.
|
8
|
+
#
|
9
|
+
# Does nothing extra for now but will be used to add generic
|
10
|
+
# configuration in the future since other Footprint::Log
|
11
|
+
# classes extend this.
|
7
12
|
class Basic < Logger
|
8
13
|
|
14
|
+
# Sets the default logdev as nil
|
9
15
|
def initialize logdev = nil, shift_age = 0, shift_size = 1048576
|
10
16
|
super
|
11
17
|
end
|
@@ -4,8 +4,14 @@ module Footprint
|
|
4
4
|
|
5
5
|
module Log
|
6
6
|
|
7
|
+
# Class that extends the Footprint::Log::Basic and
|
8
|
+
# adds a write method which logs on error level.
|
9
|
+
#
|
10
|
+
# This Class can be used as a File instance to
|
11
|
+
# write in log.
|
7
12
|
class ErrorFile < Basic
|
8
13
|
|
14
|
+
# Logs the message on error level on logger.
|
9
15
|
def write(message)
|
10
16
|
error message
|
11
17
|
end
|
data/lib/footprint/log/gelf.rb
CHANGED
@@ -4,6 +4,11 @@ module Footprint
|
|
4
4
|
|
5
5
|
module Log
|
6
6
|
|
7
|
+
# Class that extends the GELF::Logger.
|
8
|
+
#
|
9
|
+
# Does nothing extra for now but will be used to add generic
|
10
|
+
# configuration in the future since other Footprint::Log
|
11
|
+
# classes will extend this.
|
7
12
|
class Gelf < GELF::Logger
|
8
13
|
|
9
14
|
end
|
@@ -4,8 +4,14 @@ module Footprint
|
|
4
4
|
|
5
5
|
module Log
|
6
6
|
|
7
|
+
# Class that extends the Footprint::Log::Basic and
|
8
|
+
# adds a write method which logs on info level.
|
9
|
+
#
|
10
|
+
# This Class can be used as a File instance to
|
11
|
+
# write in log.
|
7
12
|
class OutFile < Basic
|
8
13
|
|
14
|
+
# Logs the message on info level on logger.
|
9
15
|
def write(message)
|
10
16
|
info message
|
11
17
|
end
|
data/lib/footprint/middleware.rb
CHANGED
@@ -3,10 +3,25 @@ require_relative '../log'
|
|
3
3
|
|
4
4
|
module Footprint
|
5
5
|
|
6
|
+
#
|
7
|
+
# Class that is actually the Middleware we use to decorate
|
8
|
+
# the application with loggers, taking advantage of the @env.
|
9
|
+
#
|
6
10
|
class Middleware
|
7
11
|
|
12
|
+
# @app = the instance of the application that uses this middleware.
|
13
|
+
# @logger = the instance of the logger used to decorate the Rack application.
|
8
14
|
attr_accessor :app, :logger
|
9
15
|
|
16
|
+
# Initialize the Middleware with the app that uses this
|
17
|
+
# Middleware and an optional block.
|
18
|
+
#
|
19
|
+
# Sets as the default logger a Footprint::Log::Basic on STDOUT.
|
20
|
+
#
|
21
|
+
# Decorate the given app with a new method called logger,
|
22
|
+
# that will return the instance of the logger from the env.
|
23
|
+
#
|
24
|
+
# If any block is given, a instance_eval is called.
|
10
25
|
def initialize(app, &block)
|
11
26
|
|
12
27
|
@app = app
|
@@ -21,11 +36,19 @@ module Footprint
|
|
21
36
|
self.instance_eval &block if block
|
22
37
|
end
|
23
38
|
|
39
|
+
|
40
|
+
# The current instance of the logger is set on env[:footprint_logger]
|
41
|
+
# and the app is called further with the enriched env.
|
24
42
|
def call(env)
|
25
43
|
env[:footprint_logger] = @logger
|
26
44
|
@app.call env
|
27
45
|
end
|
28
46
|
|
47
|
+
# Initialize the current instance of the logger with
|
48
|
+
# a new instance of the class given as parameter.
|
49
|
+
#
|
50
|
+
# The initialization of the class given is done using
|
51
|
+
# the second parameter.
|
29
52
|
def set clazz, *args
|
30
53
|
@logger = clazz.send(:new, *args)
|
31
54
|
end
|