uc3-dmp-cloudwatch 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +3 -0
- data/lib/uc3-dmp-cloudwatch/logger.rb +62 -0
- data/lib/uc3-dmp-cloudwatch/version.rb +5 -0
- data/lib/uc3-dmp-cloudwatch.rb +9 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f71f6ea7b2f3dc39de9eab5bf201e93899cb1537ca935a144d5e4eb5e9e42d9c
|
4
|
+
data.tar.gz: 9dcc25d1cb233a77508d35541bf217ebf43834bbbdf01039c71e196333c97ca3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 272f2017c217f5f79fb92e5b22e589f16df76d7a77af39bb964a5ad833dea458187d67809ed9e19917b5ddbab9271efc0d2ddce3137be85776fb044dca9a09c7
|
7
|
+
data.tar.gz: 3ffe51067739dc79e82222f1631f0717d77c9a752507f0191118987bd3f55ca55dfea7b77af01a29c249355a89d604852dbad5a7db26feba3814a2f3f6fc47f3
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Uc3DmpCloudwatch
|
4
|
+
class LoggerError < StandardError; end
|
5
|
+
|
6
|
+
# Helper functions for working with Dynamo JSON
|
7
|
+
class Logger
|
8
|
+
attr_accessor :source, :event, :request_id, :level
|
9
|
+
|
10
|
+
LOG_LEVELS = %w[none error info debug]
|
11
|
+
|
12
|
+
def initialize(**args)
|
13
|
+
@level = args.fetch(:level, 'info')&.to_s&.downcase
|
14
|
+
@level = 'info' unless LOG_LEVELS.include?(@level)
|
15
|
+
|
16
|
+
@source = args[:source]
|
17
|
+
@event = args[:event]
|
18
|
+
@request_id = args[:request_id]
|
19
|
+
end
|
20
|
+
|
21
|
+
def error(message:, details: {})
|
22
|
+
return false if @level == 'none' || message.nil?
|
23
|
+
|
24
|
+
_format_msg(mode: 'error', msg: message)
|
25
|
+
_format_msg(mode: 'error', msg: details) unless details.nil? || (details.is_a?(Hash) && details.keys.empty?)
|
26
|
+
_log_event(mode: 'error')
|
27
|
+
end
|
28
|
+
|
29
|
+
def info(message:, details: {})
|
30
|
+
return false if %w[none error].include?(@level) || message.nil?
|
31
|
+
|
32
|
+
_format_msg(mode: 'info', msg: message)
|
33
|
+
_format_msg(mode: 'info', msg: details) unless details.nil? || (details.is_a?(Hash) && details.keys.empty?)
|
34
|
+
end
|
35
|
+
|
36
|
+
def debug(message:, details: {})
|
37
|
+
return false if %w[none error info].include?(@level) || message.nil?
|
38
|
+
|
39
|
+
_format_msg(mode: 'debug', msg: message)
|
40
|
+
_format_msg(mode: 'debug', msg: details) unless details.nil? || (details.is_a?(Hash) && details.keys.empty?)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Format the start of the message with a prefix and the AWS request id if available
|
46
|
+
def _prefix(prefix: 'INFO')
|
47
|
+
prefix = @request_id.nil? ? "#{prefix} " : "#{prefix} RequestId: #{@request_id},"
|
48
|
+
prefix += " SOURCE: #{@source}," unless @source.nil?
|
49
|
+
end
|
50
|
+
|
51
|
+
# Format the message
|
52
|
+
def _format_msg(mode: 'info', msg:)
|
53
|
+
message = msg.is_a?(Array) ? msg.join(', ') : msg
|
54
|
+
puts "#{_prefix(prefix: mode.upcase)} #{message.is_a?(String) ? "MESSAGE: #{message}" : "PAYLOAD: #{message}"}"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Write the event Hash
|
58
|
+
def _log_event(mode: 'info')
|
59
|
+
puts "#{_prefix(prefix: mode)} Event: #{@event}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uc3-dmp-cloudwatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Riley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 11.1.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 11.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.9.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.50.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.50.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.20.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.20.0
|
69
|
+
description: Helper for working with Lambda logs
|
70
|
+
email:
|
71
|
+
- brian.riley@ucop.edu
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- README.md
|
77
|
+
- lib/uc3-dmp-cloudwatch.rb
|
78
|
+
- lib/uc3-dmp-cloudwatch/logger.rb
|
79
|
+
- lib/uc3-dmp-cloudwatch/version.rb
|
80
|
+
homepage: https://github.com/CDLUC3/dmp-hub-cfn/blob/main/src/sam/gems/uc3-dmp-cloudwatch
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata:
|
84
|
+
rubygems_mfa_required: 'false'
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.7'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.1.6
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: DMPTool gem that provides support for writing standardized logs to CloudWatch
|
104
|
+
test_files: []
|