transaction_logger 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +33 -9
- data/lib/transaction_logger/version.rb +1 -1
- data/lib/transaction_logger.rb +10 -0
- data/transaction_logger.gemspec +5 -5
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dcfe3a7f8cbdde324e95e0a246a411907faf9f5
|
4
|
+
data.tar.gz: c7747c2a99b7705e3689b317276969e41e902b3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81fb304e54412d6ed784684b14b64145ee3796b0fe841fb4b41485cd8790068c9b703cc07fe89da23b629f935f3b6cf1d75797544b3bd81a73f9cef49c79f64f
|
7
|
+
data.tar.gz: 47e00a81952e0633aa9974bea50b7cf9c79f6c72d8899baa315be4330615a43c9d9210409ebedf31d7d89838b46bdb1ff058cc73d8387b0415d0c5935c068ca1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Blinkist TransactionLogger
|
2
|
-
[ ![Codeship Status for blinkist/transaction_logger](https://codeship.com/projects/fb9745c0-edc7-0132-b6b1-1efd3f886df2/status?branch=master)](https://codeship.com/projects/84119) [![Code Climate](https://codeclimate.com/github/blinkist/transaction_logger/badges/gpa.svg)](https://codeclimate.com/github/blinkist/transaction_logger)
|
2
|
+
[ ![Codeship Status for blinkist/transaction_logger](https://codeship.com/projects/fb9745c0-edc7-0132-b6b1-1efd3f886df2/status?branch=master)](https://codeship.com/projects/84119) [![Code Climate](https://codeclimate.com/github/blinkist/transaction_logger/badges/gpa.svg)](https://codeclimate.com/github/blinkist/transaction_logger) [![Dependency Status](https://www.versioneye.com/ruby/transaction_logger/badge.svg)](https://www.versioneye.com/ruby/transaction_logger/)
|
3
3
|
|
4
4
|
Business Transactions Logger for Ruby that compiles contextual logging information and can send it to a configured logging service such as Logger or Loggly in a nested hash.
|
5
5
|
|
@@ -34,6 +34,19 @@ logger = Logger.new STDOUT # Ruby default logger setup
|
|
34
34
|
TransactionLogger.logger = logger
|
35
35
|
```
|
36
36
|
|
37
|
+
Calling Transaction_Logger.logger with no parameter sets the logger to a new instance of Logger as shown above.
|
38
|
+
|
39
|
+
You can add a prefix to every hash key in the log by using the class method log_prefix:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
TransactionLogger.log_prefix = "transaction_logger_"
|
43
|
+
# {
|
44
|
+
# "transaction_logger_name" => "some name"
|
45
|
+
# "transaction_logger_context" => { "user_id" => 1 }
|
46
|
+
# ...
|
47
|
+
# }
|
48
|
+
```
|
49
|
+
|
37
50
|
Wrap a business transaction method with a TransactionLogger lambda:
|
38
51
|
|
39
52
|
```ruby
|
@@ -54,6 +67,17 @@ t.log "A message you want logged"
|
|
54
67
|
|
55
68
|
### Example
|
56
69
|
|
70
|
+
Initial setup, in a config file:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# Sets output to new instance of Logger
|
74
|
+
TransactionLogger.logger
|
75
|
+
|
76
|
+
# Sets the prefix of each hash key in the log to "transaction_"
|
77
|
+
# eg. An error message has key: "transaction_error_message"
|
78
|
+
TransactionLogger.log_prefix = "transaction_"
|
79
|
+
```
|
80
|
+
|
57
81
|
Here is a transaction that raises an error:
|
58
82
|
|
59
83
|
```ruby
|
@@ -77,17 +101,17 @@ The expected output is:
|
|
77
101
|
|
78
102
|
```json
|
79
103
|
{
|
80
|
-
"
|
81
|
-
"
|
104
|
+
"name": "ExampleClass.some_method",
|
105
|
+
"context": {
|
82
106
|
"some_id": 12
|
83
107
|
},
|
84
|
-
"
|
85
|
-
"
|
86
|
-
"
|
108
|
+
"duration": 0.112,
|
109
|
+
"history": [{
|
110
|
+
"info": "Trying something complex"
|
87
111
|
}, {
|
88
|
-
"
|
89
|
-
"
|
90
|
-
"
|
112
|
+
"error_message": "Error",
|
113
|
+
"error_class": "RuntimeError",
|
114
|
+
"error_backtrace": [
|
91
115
|
"example.rb:84:in `block in nested_method'",
|
92
116
|
".../TransactionLogger_Example/transaction_logger.rb:26:in `call'",
|
93
117
|
".../TransactionLogger_Example/transaction_logger.rb:26:in `run'",
|
data/lib/transaction_logger.rb
CHANGED
@@ -54,12 +54,22 @@ class TransactionLogger
|
|
54
54
|
@@logger ||= Logger.new(STDOUT)
|
55
55
|
end
|
56
56
|
|
57
|
+
# Sets the hash keys on the TransactionLogger's log to have a prefix.
|
57
58
|
#
|
59
|
+
# Using .log_prefix "str_", the output of the log hash will contain keys prefixed
|
60
|
+
# with "str_", such as { "str_name" => "Class.method" }.
|
61
|
+
#
|
62
|
+
# @param prefix [#to_s] Any String or Object that responds to to_s
|
58
63
|
#
|
59
64
|
def self.log_prefix=(prefix)
|
60
65
|
@@prefix = "#{prefix}"
|
61
66
|
end
|
62
67
|
|
68
|
+
# @private
|
69
|
+
# Returns the log_prefix
|
70
|
+
#
|
71
|
+
# @return [String] The currently stored prefix.
|
72
|
+
#
|
63
73
|
def self.log_prefix
|
64
74
|
@@prefix
|
65
75
|
end
|
data/transaction_logger.gemspec
CHANGED
@@ -9,11 +9,11 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["John Donner", "Sebastian Schleicher"]
|
10
10
|
spec.email = ["johnbdonner@gmail.com", "sebastian.julius@gmail.com"]
|
11
11
|
spec.summary = %q{Contextual Business Transaction Logger for Ruby}
|
12
|
-
spec.description = %q{A logger that silently collects information in the
|
13
|
-
background and when an error is raised, logs a hash either
|
14
|
-
out to the System or pushes the log to a service such as
|
15
|
-
Loggly. The log hash contains information such as the
|
16
|
-
backtrace, any logs from calling classes and methods,
|
12
|
+
spec.description = %q{A logger that silently collects information in the
|
13
|
+
background and when an error is raised, logs a hash either
|
14
|
+
out to the System or pushes the log to a service such as
|
15
|
+
Loggly. The log hash contains information such as the
|
16
|
+
backtrace, any logs from calling classes and methods,
|
17
17
|
and configurable contextual information.}
|
18
18
|
spec.homepage = "https://github.com/blinkist/transaction_logger"
|
19
19
|
spec.license = "MIT"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transaction_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Donner
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-07-
|
12
|
+
date: 2015-07-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -109,13 +109,12 @@ dependencies:
|
|
109
109
|
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
|
-
description:
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
and configurable contextual information.
|
112
|
+
description: "A logger that silently collects information in the\n background
|
113
|
+
and when an error is raised, logs a hash either\n out to
|
114
|
+
the System or pushes the log to a service such as\n Loggly.
|
115
|
+
The log hash contains information such as the\n backtrace,
|
116
|
+
any logs from calling classes and methods, \n and configurable
|
117
|
+
contextual information."
|
119
118
|
email:
|
120
119
|
- johnbdonner@gmail.com
|
121
120
|
- sebastian.julius@gmail.com
|