chili_logger 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,77 @@
1
+ require 'logs_coverage/coverage_writer'
2
+ require 'helpers/rails_backtrace_cleaner'
3
+ require 'message_writer/aws_ops_metadata'
4
+
5
+ # class for centralizing Creative's logging logic
6
+ class ChiliLogger
7
+ # class for writing log messages
8
+ class MessageWriter
9
+ def initialize(config)
10
+ @env = config[:env] || 'not_specified'
11
+ @layer = config[:layer] || 'not_specified'
12
+ @server_url = config[:server_url] || 'not_specified'
13
+ @cloud_provider = config[:cloud_provider]
14
+ @backtrace_cleaner = RailsBacktraceCleaner.new
15
+ end
16
+
17
+ def write(desc = {}, agent = 'not_specified', main_content = {})
18
+ return if ChiliLogger.instance.deactivated
19
+
20
+ desc ||= {}
21
+ main_content ||= {}
22
+
23
+ main_content.merge!({ backtrace: @backtrace_cleaner.clean(caller) })
24
+ update_logs_coverage(desc, main_content)
25
+ message_hash(desc, agent, main_content)
26
+ end
27
+
28
+ def write_description_tag(desc)
29
+ env = desc[:env] || @env
30
+ layer = desc[:layer] || @layer
31
+ type = desc[:type] || 'not_specified'
32
+ service = desc[:service] || 'not_specified'
33
+ action = desc[:action] || 'not_specified'
34
+
35
+ "#{env}.#{layer}.#{type}.#{service}.#{action}"
36
+ end
37
+
38
+ private
39
+
40
+ # uses message infos to keep logs_coverage up to date with what logs are being generated in the application
41
+ def update_logs_coverage(desc, main_content)
42
+ backtrace = main_content[:backtrace] || @backtrace_cleaner.clean(caller)
43
+ CoverageWriter.write(desc, backtrace)
44
+ end
45
+
46
+ # rubocop:disable Metrics/MethodLength
47
+ def message_hash(desc, agent, main_content)
48
+ {
49
+ desc: write_description_tag(desc),
50
+ env: @env,
51
+ layer: @layer,
52
+ type: desc[:type] || 'not_specified',
53
+ service: desc[:service] || 'not_specified',
54
+ action: desc[:action] || 'not_specified',
55
+ user_info: agent || 'not_specified',
56
+ timestamp: DateTime.now,
57
+ "#{desc[:type]}": main_content || {},
58
+ ops_metadata: write_ops_metadata
59
+ }
60
+ end
61
+ # rubocop:enable Metrics/MethodLength
62
+
63
+ def write_ops_metadata
64
+ provider = @cloud_provider.is_a?(String) ? @cloud_provider.to_sym : @cloud_provider
65
+ {
66
+ server_url: @server_url,
67
+ cloud: cloud_metadata[provider]
68
+ }
69
+ end
70
+
71
+ def cloud_metadata
72
+ {
73
+ aws: AwsOpsMetadata.write
74
+ }
75
+ end
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chili_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - lucas sandeville
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bunny
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: placeholder
42
+ email:
43
+ - lucas.sandeville@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".byebug_history"
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".rubocop.yml"
52
+ - ".travis.yml"
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - chili_logger.gemspec
61
+ - lib/brokers/rabbit_broker.rb
62
+ - lib/chili_logger.rb
63
+ - lib/chili_logger/version.rb
64
+ - lib/current_log_accessor.rb
65
+ - lib/errors/config_error.rb
66
+ - lib/errors/rabbitmq_error.rb
67
+ - lib/helpers/rails_backtrace_cleaner.rb
68
+ - lib/logs_coverage/chili_logger_coverage.yml
69
+ - lib/logs_coverage/coverage_writer.rb
70
+ - lib/logs_coverage/levantamento_provisório.yaml
71
+ - lib/message_writer/aws_ops_metadata.rb
72
+ - lib/message_writer/message_writer.rb
73
+ homepage: https://gitlab.com/chiligumdev/chili_logger
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.3.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.0.6
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: placeholder
96
+ test_files: []