ama_logger 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b52fbe18b4b40eecccdf00bee03c7d795d948da303f735ed2247323e045cc8f5
4
- data.tar.gz: 0c63ed4489a0af404855c83f414dfb29076cbbd6c592b412b27460d7606081fa
3
+ metadata.gz: 05a03ef82b3bd55b8ba6c0df04d5f59aea5c87224ce1988a4554dde3b5071cd8
4
+ data.tar.gz: e8881157ae2a827a899ef4fd54ad4a5d17a26362b5521dffd18d0da2eade1ddc
5
5
  SHA512:
6
- metadata.gz: 4076394cabb942a660282acd818e96509c1c5b683f4405ffd92e6eb53d44977c52906a5e675a49fe25f5a9a843317aadb2764664303e01b235c468884a3235e6
7
- data.tar.gz: a7b21b6df82c4c0dce68c9e98c791d095fab3c91ef5846e2b176f5985163b7b89080992dc86b794df864a0e9c35129a71f9b4d19de2a8b7601f62192ae13f818
6
+ metadata.gz: 1fe8ccc8d7efc2d7ac749f79924e689467a44a4c4e711e240e9c108a3c4534e657d46bde8b17ad3f0009894398d77cada08004d47f3ea319eb093301cf42ddb3
7
+ data.tar.gz: 8b2ffdc0f264d2b896eaa9ed345cdccfedc59d6e9467e35a19a0112f5296b09b0d2ddd022551405d9aff8aec2f8dc7b02d459bddf9b52fa2240165b16b862039
data/README.md CHANGED
@@ -93,6 +93,24 @@ ActiveJob::Base.logger = Ama::Logger.stringified_hash(
93
93
  )
94
94
  ```
95
95
 
96
+ ### Mixins
97
+
98
+ #### Ama::Logger::Mixins::LambdaHandler
99
+
100
+ Defines a method that accepts the `event:` and `context:` named arguments as used in an AWS lambda function and logs the input event and output response.
101
+
102
+ ```ruby
103
+ class MyClass
104
+ extend Ama::Logger::Mixins::LambdaHandler
105
+
106
+ define_lambda_handler(:handler) do |event, context|
107
+ # do something
108
+ end
109
+ end
110
+
111
+ MyClass.handle(event: event, context: context) # => the output of lambda handler
112
+ ```
113
+
96
114
  ## Contributing
97
115
 
98
116
  Bug reports and pull requests are welcome on GitHub at https://github.com/amaabca/ama_logger.
@@ -23,14 +23,14 @@ module Ama
23
23
  Pathname.new(Gem.loaded_specs['ama_logger'].full_gem_path)
24
24
  end
25
25
 
26
- def lambda(io = STDOUT, *args)
27
- ::Logger.new(io, *args).tap do |instance|
26
+ def lambda(io = STDOUT, **args)
27
+ ::Logger.new(io, **args).tap do |instance|
28
28
  instance.formatter = Ama::Logger::Formatter::Lambda.new
29
29
  end
30
30
  end
31
31
 
32
- def json(io = STDOUT, *args)
33
- ::Logger.new(io, *args).tap do |instance|
32
+ def json(io = STDOUT, **args)
33
+ ::Logger.new(io, **args).tap do |instance|
34
34
  instance.formatter = Ama::Logger::Formatter::Json.new
35
35
  end
36
36
  end
@@ -10,3 +10,4 @@ require_relative 'version'
10
10
  require_relative 'formatter/lambda'
11
11
  require_relative 'formatter/json'
12
12
  require_relative 'formatter/stringified_hash'
13
+ require_relative 'mixins/lambda_handler'
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ama
4
+ module Logger
5
+ module Mixins
6
+ module LambdaHandler
7
+ def define_lambda_handler(name)
8
+ define_singleton_method(name) do |event:, context:|
9
+ Ama.logger.info(
10
+ context: context,
11
+ event_name: 'log.info',
12
+ metric_name: 'lambda.input',
13
+ metric_content: event.to_json
14
+ )
15
+ yield(event, context).tap do |response|
16
+ Ama.logger.info(
17
+ context: context,
18
+ event_name: 'log.info',
19
+ metric_name: 'lambda.output',
20
+ metric_content: response.to_json
21
+ )
22
+ end
23
+ rescue StandardError => e
24
+ Ama.logger.info(
25
+ context: context,
26
+ event_name: 'log.error',
27
+ metric_name: 'lambda.error',
28
+ metric_content: e.message,
29
+ exception: e
30
+ )
31
+ raise
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ama
4
4
  module Logger
5
- VERSION = '1.2.1'
5
+ VERSION = '1.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ama_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Doyle
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2020-04-16 00:00:00.000000000 Z
15
+ date: 2020-05-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
@@ -142,6 +142,7 @@ files:
142
142
  - lib/ama/logger/formatter/json.rb
143
143
  - lib/ama/logger/formatter/lambda.rb
144
144
  - lib/ama/logger/formatter/stringified_hash.rb
145
+ - lib/ama/logger/mixins/lambda_handler.rb
145
146
  - lib/ama/logger/version.rb
146
147
  - lib/ama_logger.rb
147
148
  homepage: https://github.com/amaabca/ama_logger
@@ -163,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  - !ruby/object:Gem::Version
164
165
  version: '0'
165
166
  requirements: []
166
- rubyforge_project:
167
- rubygems_version: 2.7.6
167
+ rubygems_version: 3.1.2
168
168
  signing_key:
169
169
  specification_version: 4
170
170
  summary: Implementation of AMA's standard logging format