bamm_log 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +16 -15
- data/hola.gemspec +0 -2
- data/lib/bamm_log/exception_middleware.rb +25 -9
- data/lib/bamm_log/version.rb +1 -1
- data/lib/bamm_log.rb +47 -15
- data/pkg/bamm_log-0.0.5.gem +0 -0
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDJlNmU4NzcyYTljNTI5MjhiZDJlNDFhMGJmNjUzNWM4YjgwYjlhYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDU5MTFkM2NmNjY0ZTc4MjA5ZWYzOTA4NGMwMjg1ZmRiZjMyZDk4YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGE3Mzg5OTAyZWJiYzEzNTk4YjhkZTc2ZjIwOTM0YjRkMGU2YzFkYjdjN2Vh
|
10
|
+
MDM3NjcxOGE3OTZlYjYzZTRkMjU4ODZmN2IyZTQ1Zjk2Y2E1Y2IyZDU0ZmQx
|
11
|
+
OGE5NTUxZTFiM2YzM2RmNjA2YjM4MmZiNGEwNmQ3NzliZjA3MjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGJhMDk0ODE0ZjdlYzJiYWRiZTg4Mzc1MDVjY2NkMGUwMzJkZmFjODU3MmM5
|
14
|
+
YmIzNzQ2NDAyMWUwOWRmM2NhNWJiYzU4YzkyZTYxMWMyYTc0NTQyZWI2Zjgz
|
15
|
+
Y2FlM2U4ZmY5YjFmNWUxYjZkMjE2YjhlNTA0OTcyM2E5OWZiMGE=
|
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Bamm Log
|
2
|
+
A Sinatra Logger
|
2
3
|
|
3
|
-
|
4
|
-
|
4
|
+
For the record.. this is a WIP gem..
|
5
|
+
|
6
|
+
By default Sinatra logs this:
|
5
7
|
|
6
8
|
|
7
9
|
> <sub>127.0.0.1 - - [25/Aug/2014 17:23:11] "GET /page HTTP/1.1" 200 6736 2.5322</sub><br />
|
@@ -12,8 +14,7 @@ By default sinatra logs this:
|
|
12
14
|
|
13
15
|
> <sub>127.0.0.1 - - [25/Aug/2014 17:24:33] "POST /error HTTP/1.1" 500 5443 0.1238</sub>
|
14
16
|
|
15
|
-
This page returns 500 for what? You can check
|
16
|
-
|
17
|
+
This page returns 500 for what? You can check your apache error.log file or you can log everything to one file, like Rails do.
|
17
18
|
|
18
19
|
After reading some implementations, I joined some ideas and created this gem.
|
19
20
|
It's not tested yet, so.. don't use it on production.
|
@@ -50,21 +51,21 @@ Or install it yourself as:
|
|
50
51
|
|
51
52
|
## Usage
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
configure :staging do
|
56
|
-
include BammLog::Logger
|
57
|
-
end
|
54
|
+
Include in your app
|
58
55
|
|
59
|
-
|
60
|
-
# being logged to the same "environment".log file
|
61
|
-
def logger
|
62
|
-
BammLog.logger
|
63
|
-
end
|
56
|
+
class App < Sinatra::Base
|
64
57
|
|
58
|
+
include BammLog::Logger
|
59
|
+
|
65
60
|
end
|
66
61
|
|
67
|
-
|
62
|
+
And add manual logs
|
63
|
+
|
64
|
+
BammLog.print "This is a log"
|
65
|
+
|
66
|
+
|
67
|
+
In development environment, bamm_log logs to your terminal.<br />
|
68
|
+
In live environment, training or staging, bamm_log creates a file with the name "environment".log in /log and logs all the accesses and errors from your application.
|
68
69
|
|
69
70
|
## Contributing
|
70
71
|
|
data/hola.gemspec
CHANGED
@@ -1,40 +1,56 @@
|
|
1
1
|
module BammLog
|
2
2
|
class ExceptionMiddleware
|
3
3
|
|
4
|
+
attr_reader :env
|
5
|
+
|
4
6
|
def initialize(app, options={})
|
5
7
|
@app = app
|
6
8
|
end
|
7
9
|
|
8
10
|
def call(env)
|
11
|
+
@env = env
|
9
12
|
|
10
13
|
begin
|
11
|
-
|
12
|
-
|
14
|
+
log_start
|
15
|
+
log_params
|
13
16
|
@app.call(env)
|
14
17
|
rescue Exception => e
|
15
|
-
log_exception
|
18
|
+
log_exception
|
16
19
|
@app.call(env)
|
17
20
|
end
|
18
|
-
|
19
21
|
end
|
20
22
|
|
21
23
|
private
|
22
24
|
|
23
|
-
def request_params
|
24
|
-
if
|
25
|
+
def request_params
|
26
|
+
if request_body_params?
|
25
27
|
env['rack.request.form_hash']
|
26
28
|
else
|
27
29
|
Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
def
|
32
|
-
BammLog.
|
33
|
+
def log_start
|
34
|
+
BammLog.print "Started #{env['REQUEST_METHOD']} \"#{env['REQUEST_URI']}\""
|
35
|
+
end
|
36
|
+
|
37
|
+
def log_params
|
38
|
+
BammLog.print "Parameters: #{request_params.inspect}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def log_exception
|
42
|
+
e = env['sinatra.error']
|
43
|
+
|
44
|
+
BammLog.print "Bamm! #{e.class}: #{e.message}"
|
33
45
|
|
34
46
|
e.backtrace.each do |line|
|
35
|
-
BammLog.
|
47
|
+
BammLog.print "#{line}"
|
36
48
|
end
|
37
49
|
end
|
38
50
|
|
51
|
+
def request_body_params?
|
52
|
+
['POST', 'PUT', 'PATCH'].include? env['REQUEST_METHOD']
|
53
|
+
end
|
54
|
+
|
39
55
|
end
|
40
56
|
end
|
data/lib/bamm_log/version.rb
CHANGED
data/lib/bamm_log.rb
CHANGED
@@ -6,35 +6,67 @@ module BammLog
|
|
6
6
|
module Logger
|
7
7
|
|
8
8
|
def self.included(klass)
|
9
|
-
|
9
|
+
klass.configure do
|
10
|
+
klass.enable :logging
|
11
|
+
klass.use BammLog::ExceptionMiddleware
|
12
|
+
end
|
13
|
+
|
14
|
+
klass.include BammLog::Formatter
|
15
|
+
|
16
|
+
@instance ||= if klass.environment != :development
|
17
|
+
EnvLogger.new(klass)
|
18
|
+
else
|
19
|
+
DevLogger.new
|
20
|
+
end
|
21
|
+
|
22
|
+
klass.configure do
|
23
|
+
klass.use Rack::CommonLogger, BammLog::Logger.instance
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.instance
|
28
|
+
@instance
|
29
|
+
end
|
30
|
+
|
31
|
+
# ------------------------------------------------------------- loggers
|
32
|
+
|
33
|
+
class EnvLogger
|
34
|
+
|
35
|
+
attr_accessor :logger
|
10
36
|
|
11
|
-
def
|
12
|
-
|
37
|
+
def initialize(app)
|
38
|
+
self.logger = ::Logger.new(EnvLogger.log_file(app)).tap do |logger|
|
13
39
|
::Logger.class_eval { alias :write :'<<' }
|
14
40
|
logger.level = ::Logger::INFO
|
15
41
|
end
|
16
42
|
end
|
17
43
|
|
18
|
-
def self.log_file
|
19
|
-
@log_file ||= File.new("#{
|
44
|
+
def self.log_file(app)
|
45
|
+
@log_file ||= File.new("#{app.root}/log/#{app.environment}.log", 'a+').tap do |log_file|
|
20
46
|
log_file.sync = true
|
21
47
|
end
|
22
48
|
end
|
23
49
|
|
24
|
-
|
25
|
-
|
26
|
-
klass.configure do
|
27
|
-
klass.enable :logging
|
28
|
-
klass.use Rack::CommonLogger, BammLog::Logger.instance
|
29
|
-
klass.use BammLog::ExceptionMiddleware
|
50
|
+
def method_missing(method, args, &block)
|
51
|
+
logger.send(method, args, &block)
|
30
52
|
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class DevLogger
|
57
|
+
|
58
|
+
def info(text)
|
59
|
+
puts BammLog::Formatter.call_formatted(Time.now, text)
|
60
|
+
end
|
61
|
+
|
31
62
|
end
|
32
|
-
|
33
|
-
end
|
34
63
|
|
35
|
-
def logger
|
36
|
-
BammLog::Logger.instance
|
37
64
|
end
|
38
65
|
|
66
|
+
def print(message)
|
67
|
+
BammLog::Logger.instance.info message
|
68
|
+
end
|
69
|
+
|
39
70
|
extend self
|
71
|
+
|
40
72
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bamm_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joaquim Adráz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: pry
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ! '>='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ! '>='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
11
|
+
date: 2014-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description:
|
28
14
|
email:
|
29
15
|
- joaquim.adraz@gmail.com
|
@@ -43,6 +29,7 @@ files:
|
|
43
29
|
- pkg/bamm_log-0.0.2.gem
|
44
30
|
- pkg/bamm_log-0.0.3.gem
|
45
31
|
- pkg/bamm_log-0.0.4.gem
|
32
|
+
- pkg/bamm_log-0.0.5.gem
|
46
33
|
homepage: https://github.com/joaquimadraz/bamm_log
|
47
34
|
licenses:
|
48
35
|
- MIT
|