zgcp_toolkit 0.1.0 → 1.0.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: fdd5f30aab3e292d7eefa9c362a0e79129cfc39d48c85b74822377d80a30cd91
4
- data.tar.gz: 8f0e40f5d92bad0d83c8e856b2d81d1dc347987fb28e1e963cdeb8e29d855b3d
3
+ metadata.gz: 84c4f7b62ed93f221db66092956a7453fd48b7ff1c89b2f826c8c4a75e265cc5
4
+ data.tar.gz: 19455250ff04e244d99487919385aabc21337289457780beab27663b7fb3f639
5
5
  SHA512:
6
- metadata.gz: 462b117371427824f07fc8caf86b9d2af58e3304ebf38081e687e8c39264981a674600da0c6c69de9150d33a8975d7956af05ceab1a8ecd05d2f648d270a5590
7
- data.tar.gz: be469a18442677b5ffddc406e029941c6cda7d9daa596d227f4785960d0f3e1801a7c49f28b5500ddd0d8caa80d8b56f4c0d06b7682ae89f833bf844b93d0e66
6
+ metadata.gz: 06ae78cb77e1ad779e7e19e1093b47dd2e2ee96ed32f6020a25dc1b49d4b1e2c4ee442f326f5603820dd02170b515e33ae7e142d5264104666fa9a131cf9a8a6
7
+ data.tar.gz: 0bf4ee4bca3bc738a4ea06e9b18a7cef34ece61e5c90353767cfc8bec4b7cd438bd7501a1179b3d00b34cf96226dc16b747b3aac20a6821837d489bb12ad474a
data/README.md CHANGED
@@ -22,7 +22,6 @@ Next, you need to run the generator:
22
22
  $ rails generate zgcp_toolkit
23
23
 
24
24
  ## Logger
25
- Each rake task will have its own log file in Cloud Logging. The log file name on Cloud Logging are combined from the rake task `namespace`s and `task name`. The rake task also be able to access the logger object.
26
25
 
27
26
  Unexpected errors in rake tasks are caught automatically & write to a log file in Cloud Logging. And, by default, when GCP Toolkit caught an unexpected error, it push a key & value (key: `push_slack` with value: `true`) in Cloud Logging Log `jsonPayload` so that the log that should be sent on Slack can be filtered.
28
27
 
@@ -30,16 +29,17 @@ Unexpected errors in rake tasks are caught automatically & write to a log file i
30
29
 
31
30
  ```ruby
32
31
  namespace :tcv_transactions do
33
- task :daily_import do |t, logger:|
34
- logger.info("Heyyyyyy!")
35
- # The error message & backtrace are sent to Cloud Logging
36
- raise "Heyyyyyy Oops!"
32
+ task :daily_import
33
+ ZgcpToolkit::Logger.create(:log_name) do |logger|
34
+ logger.info("Heyyyyyy!") # You can log anything to console, also google cloud logging
35
+ Bug.last
36
+ end
37
37
  end
38
38
  end
39
39
  ```
40
40
 
41
41
  ```ruby
42
- logger = ZgcpToolkit::Logger.new(:any_log_name)
42
+ logger = ZgcpToolkit::Logger.new(:log_name)
43
43
  logger.info("Heyyyyyy!")
44
44
  logger.error(message: "Heyyyyy!", backtrace: ["line-1", "line-2"])
45
45
  logger.error(message: "Hello Bug !!", backtrace: ["line-1", "line-2"], push_slack: true)
@@ -50,16 +50,18 @@ logger.warn("Hey hey nyc!")
50
50
 
51
51
  ```ruby
52
52
  namespace :test_log do
53
- task do: :environment do |args, logger:|
54
- logger.send_unexpected_error_to_slack = false
55
- raise 'errors'
53
+ task do: :environment
54
+ ZgcpToolkit::Logger.create(:log_name) do |logger|
55
+ logger.send_unexpected_error_to_slack = false
56
+ raise 'errors'
57
+ end
56
58
  end
57
59
  end
58
60
  ```
59
61
 
60
62
  ### Controller
61
63
 
62
- you can send controller errors to Google Cloud Loggings
64
+ You can send controller errors to Google Cloud Loggings
63
65
 
64
66
  ```ruby
65
67
  # app/controllers/application_controller.rb
data/lib/zgcp_toolkit.rb CHANGED
@@ -3,6 +3,5 @@ require "zgcp_toolkit/version"
3
3
  module ZgcpToolkit; end
4
4
 
5
5
  require 'zgcp_toolkit/logger'
6
- require 'zgcp_toolkit/rake/task'
7
6
  require 'zgcp_toolkit/generators/templates/zgcp_toolkit'
8
7
  require 'zgcp_toolkit/generators/zgcp_toolkit_generator'
@@ -1,9 +1,3 @@
1
- require 'dry/configurable'
2
- require 'google/cloud/logging'
3
- require 'rake/task'
4
-
5
- Rake::Task.prepend(ZgcpToolkit::Rake::Task)
6
-
7
1
  loggers = [:std_out]
8
2
 
9
3
  loggers.push(:google_cloud_logging) unless Rails.env.development?
@@ -6,6 +6,8 @@ module ZgcpToolkit
6
6
  class Logger
7
7
  extend Dry::Configurable
8
8
 
9
+ REGEX_VALID_NAME = /^[a-z0-9_]+$/.freeze
10
+
9
11
  AVAILABLE_LOGGERS = {
10
12
  std_out: ZgcpToolkit::Logger::Stdout,
11
13
  google_cloud_logging: ZgcpToolkit::Logger::GoogleCloudLogging
@@ -17,6 +19,31 @@ module ZgcpToolkit
17
19
 
18
20
  class Error < StandardError; end
19
21
  class UnsupportedLogType < Error; end
22
+ class InvalidLogName < Error; end
23
+
24
+ class << self
25
+ def create(log_name)
26
+ raise InvalidLogName, "Log name is invalid. Log name regex is #{REGEX_VALID_NAME.inspect}" unless valid_name?(log_name.to_s)
27
+
28
+ logger = Logger.new(log_name.to_s)
29
+
30
+ begin
31
+ yield(logger) if block_given?
32
+ rescue StandardError => e
33
+ logger.error(e, push_slack: logger.send_unexpected_error_to_slack)
34
+ logger.flush!
35
+ end
36
+
37
+ logger
38
+ end
39
+
40
+ private
41
+
42
+ def valid_name?(log_name)
43
+ return true if log_name.match(REGEX_VALID_NAME)
44
+ false
45
+ end
46
+ end
20
47
 
21
48
  DEFAULT_BACKTRACE_LIMIT = 10
22
49
 
@@ -1,3 +1,3 @@
1
1
  module ZgcpToolkit
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zgcp_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZIGExN VeNtura developers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-01 00:00:00.000000000 Z
11
+ date: 2021-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stackdriver
@@ -60,7 +60,6 @@ files:
60
60
  - lib/zgcp_toolkit/logger.rb
61
61
  - lib/zgcp_toolkit/logger/google_cloud_logging.rb
62
62
  - lib/zgcp_toolkit/logger/stdout.rb
63
- - lib/zgcp_toolkit/rake/task.rb
64
63
  - lib/zgcp_toolkit/version.rb
65
64
  - zgcp_toolkit.gemspec
66
65
  homepage: https://github.com/ZIGExN/zgcp_toolkit
@@ -1,13 +0,0 @@
1
- module ZgcpToolkit::Rake
2
- module Task
3
- def execute(args=nil)
4
- task_name = self.name.gsub(':', '_')
5
- logger = ZgcpToolkit::Logger.new(task_name)
6
- args.with_defaults(logger: logger)
7
- super
8
- rescue StandardError => e
9
- logger.error(e, push_slack: logger.send_unexpected_error_to_slack)
10
- logger.flush!
11
- end
12
- end
13
- end