whoops_logger 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.asciidoc +134 -0
- data/VERSION +1 -1
- data/lib/whoops_logger/configuration.rb +7 -8
- data/lib/whoops_logger/message_creator.rb +2 -1
- data/whoops_logger.gemspec +4 -4
- metadata +6 -6
- data/README.rdoc +0 -19
data/README.asciidoc
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
= Whoops Logger
|
2
|
+
|
3
|
+
Use Whoops Logger to send log messages to a https://github.com/flyingmachine/whoops[Whoops] server.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Add +whoops_logger+ to your Gemfile
|
8
|
+
|
9
|
+
Add +WhoopsLogger.config.set(config_path)+ to your project, where +config_path+ is a path to a YAML file. The YAML file takes the following options:
|
10
|
+
|
11
|
+
----
|
12
|
+
:host
|
13
|
+
:http_open_timeout
|
14
|
+
:http_read_timeout,
|
15
|
+
:port
|
16
|
+
:protocol
|
17
|
+
:proxy_host,
|
18
|
+
:proxy_pass
|
19
|
+
:proxy_port
|
20
|
+
:proxy_user
|
21
|
+
:secure
|
22
|
+
----
|
23
|
+
|
24
|
+
You can also use pass a Hash to +WhoopsLogger.config.set+ instead of a path to a YAML file.
|
25
|
+
|
26
|
+
== Usage
|
27
|
+
|
28
|
+
Whoops Logger sends Messages to Whoops. Messages are created with Strategies. Below is the basic strategy found in `lib/whoops_logger/basic.rb`:
|
29
|
+
|
30
|
+
----
|
31
|
+
strategy = WhoopsLogger::Strategy.new("default::basic")
|
32
|
+
|
33
|
+
strategy.add_message_builder(:use_basic_hash) do |message, raw_data|
|
34
|
+
message.event_type = raw_data[:event_type]
|
35
|
+
message.service = raw_data[:service]
|
36
|
+
message.environment = raw_data[:environment]
|
37
|
+
message.message = raw_data[:message]
|
38
|
+
message.event_group_identifier = raw_data[:event_group_identifier]
|
39
|
+
message.event_time = raw_data[:event_time] if raw_data[:event_time]
|
40
|
+
message.details = raw_data[:details]
|
41
|
+
end
|
42
|
+
----
|
43
|
+
|
44
|
+
To use this strategy, you would call
|
45
|
+
|
46
|
+
----
|
47
|
+
WhoopsLogger.log("default::basic", {
|
48
|
+
:event_type => "your_event_type",
|
49
|
+
:service => "your_service_name",
|
50
|
+
:environment => "development",
|
51
|
+
:message => "String to Show in Whoops Event List",
|
52
|
+
:event_group_identifier => "String used to assign related events to a group",
|
53
|
+
:event_time => "Defaults to now",
|
54
|
+
:details => "A string, hash, or array of arbitrary data"
|
55
|
+
})
|
56
|
+
----
|
57
|
+
|
58
|
+
You can create as many strategies as you need. For example, in a Rails app, you could use a strategy for logging exceptions which occur during a controller action (in fact https://github.com/flyingmachine/whoops_rails_logger[there's a gem for that]). You could use a separate strategy for logging exceptions which occur during a background job. With controller actions, you care about params, sessions, and that data. That data isn't even present in background jobs, so it makes sense to use different strategies.
|
59
|
+
|
60
|
+
=== Message Builders
|
61
|
+
|
62
|
+
Each strategy consists of one or more message builders. The message builders are called in the order in which they are defined.
|
63
|
+
|
64
|
+
Internally, each Strategy stores its message builders in the array +message_builders+, and it's possible to modify that array directly if you want. For example, you might want to modify a Strategy provided by a library.
|
65
|
+
|
66
|
+
The method +add_message_builder+ is provided for convenience. Below is an example of +add_message_builder+ taken from the https://github.com/flyingmachine/whoops_rails_logger[Whoops Rails Logger]:
|
67
|
+
|
68
|
+
----
|
69
|
+
strategy.add_message_builder(:basic_details) do |message, raw_data|
|
70
|
+
message.service = self.service
|
71
|
+
message.environment = self.environment
|
72
|
+
message.event_type = "exception"
|
73
|
+
message.message = raw_data[:exception].message
|
74
|
+
message.event_time = Time.now
|
75
|
+
end
|
76
|
+
|
77
|
+
strategy.add_message_builder(:details) do |message, raw_data|
|
78
|
+
exception = raw_data[:exception]
|
79
|
+
rack_env = raw_data[:rack_env]
|
80
|
+
|
81
|
+
details = {}
|
82
|
+
details[:backtrace] = exception.backtrace.collect{ |line|
|
83
|
+
line.sub(/^#{ENV['GEM_HOME']}/, '$GEM_HOME').sub(/^#{Rails.root}/, '$Rails.root')
|
84
|
+
}
|
85
|
+
|
86
|
+
details[:http_host] = rack_env["HTTP_HOST"]
|
87
|
+
details[:params] = rack_env["action_dispatch.request.parameters"]
|
88
|
+
details[:query_string] = rack_env["QUERY_STRING"]
|
89
|
+
details[:remote_addr] = rack_env["REMOTE_ADDR"]
|
90
|
+
details[:request_method] = rack_env["REQUEST_METHOD"]
|
91
|
+
details[:server_name] = rack_env["SERVER_NAME"]
|
92
|
+
details[:session] = rack_env["rack.session"]
|
93
|
+
details[:env] = ENV
|
94
|
+
message.details = details
|
95
|
+
end
|
96
|
+
|
97
|
+
strategy.add_message_builder(:create_event_group_identifier) do |message, raw_data|
|
98
|
+
identifier = "#{raw_data[:controller]}##{raw_data[:action]}"
|
99
|
+
identifier << raw_data[:exception].backtrace.collect{|l| l.sub(Rails.root, "")}.join("\n")
|
100
|
+
message.event_group_identifier = Digest::MD5.hexdigest(identifier)
|
101
|
+
end
|
102
|
+
----
|
103
|
+
|
104
|
+
There's a bit more about message builders in the WhoopsLogger::Strategy documentation.
|
105
|
+
|
106
|
+
=== Ignore Criteria
|
107
|
+
|
108
|
+
Sometimes you want to ignore a message instead of sending it off to whoops. For example, you might not want to log "Record Not Found" exceptions in Rails. If any of the ignore criteria evaluate to true, then the message is ignored. Below is an example:
|
109
|
+
|
110
|
+
----
|
111
|
+
strategy.add_ignore_criteria(:ignore_record_not_found) do |message|
|
112
|
+
message.message == "Record Not Found"
|
113
|
+
end
|
114
|
+
|
115
|
+
strategy.add_ignore_criteria(:ignore_dev_environment) do |message|
|
116
|
+
message.environment == "development"
|
117
|
+
end
|
118
|
+
----
|
119
|
+
|
120
|
+
== Contributing to whoops_logger
|
121
|
+
|
122
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
123
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
124
|
+
* Fork the project
|
125
|
+
* Start a feature/bugfix branch
|
126
|
+
* Commit and push until you are happy with your contribution
|
127
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
128
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
129
|
+
|
130
|
+
== Copyright
|
131
|
+
|
132
|
+
Copyright (c) 2011 Daniel Higginbotham. See LICENSE.txt for
|
133
|
+
further details.
|
134
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
@@ -36,10 +36,6 @@ module WhoopsLogger
|
|
36
36
|
# The password to use when logging into your proxy server (if using a proxy)
|
37
37
|
attr_accessor :proxy_pass
|
38
38
|
|
39
|
-
# The logger used by WhoopsLogger
|
40
|
-
attr_accessor :logger
|
41
|
-
|
42
|
-
|
43
39
|
alias_method :secure?, :secure
|
44
40
|
|
45
41
|
def initialize
|
@@ -84,9 +80,12 @@ module WhoopsLogger
|
|
84
80
|
|
85
81
|
def set(config)
|
86
82
|
case config
|
87
|
-
when Hash
|
88
|
-
|
89
|
-
when
|
83
|
+
when Hash
|
84
|
+
set_with_hash(config)
|
85
|
+
when IO
|
86
|
+
set_with_io(config)
|
87
|
+
when String
|
88
|
+
set_with_string(config)
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
@@ -129,4 +128,4 @@ module WhoopsLogger
|
|
129
128
|
end
|
130
129
|
end
|
131
130
|
end
|
132
|
-
end
|
131
|
+
end
|
@@ -11,6 +11,7 @@ module WhoopsLogger
|
|
11
11
|
self.strategy = strategy
|
12
12
|
self.raw_data = raw_data
|
13
13
|
self.message = Message.new
|
14
|
+
self.message.event_time = Time.now
|
14
15
|
self.message.logger_strategy_name = strategy.respond_to?(:name) ? strategy.name : 'anonymous'
|
15
16
|
end
|
16
17
|
|
@@ -22,4 +23,4 @@ module WhoopsLogger
|
|
22
23
|
message.ignore?
|
23
24
|
end
|
24
25
|
end
|
25
|
-
end
|
26
|
+
end
|
data/whoops_logger.gemspec
CHANGED
@@ -5,16 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{whoops_logger}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Higginbotham"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-31}
|
13
13
|
s.description = %q{Handles basic notification responsibilities and allows creation of message creation strategies}
|
14
14
|
s.email = %q{daniel@flyingmachinestudios.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.asciidoc"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
"Gemfile",
|
23
23
|
"Gemfile.lock",
|
24
24
|
"LICENSE.txt",
|
25
|
-
"README.
|
25
|
+
"README.asciidoc",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"lib/whoops_logger.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whoops_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Higginbotham
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-31 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -116,14 +116,14 @@ extensions: []
|
|
116
116
|
|
117
117
|
extra_rdoc_files:
|
118
118
|
- LICENSE.txt
|
119
|
-
- README.
|
119
|
+
- README.asciidoc
|
120
120
|
files:
|
121
121
|
- .document
|
122
122
|
- .rspec
|
123
123
|
- Gemfile
|
124
124
|
- Gemfile.lock
|
125
125
|
- LICENSE.txt
|
126
|
-
- README.
|
126
|
+
- README.asciidoc
|
127
127
|
- Rakefile
|
128
128
|
- VERSION
|
129
129
|
- lib/whoops_logger.rb
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= whoops_logger
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to whoops_logger
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
-
* Fork the project
|
10
|
-
* Start a feature/bugfix branch
|
11
|
-
* Commit and push until you are happy with your contribution
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2011 Daniel Higginbotham. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|