zgcp_toolkit 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -10
- data/lib/zgcp_toolkit.rb +0 -1
- data/lib/zgcp_toolkit/generators/templates/zgcp_toolkit.rb +0 -6
- data/lib/zgcp_toolkit/logger.rb +27 -0
- data/lib/zgcp_toolkit/version.rb +1 -1
- metadata +2 -3
- data/lib/zgcp_toolkit/rake/task.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84c4f7b62ed93f221db66092956a7453fd48b7ff1c89b2f826c8c4a75e265cc5
|
4
|
+
data.tar.gz: 19455250ff04e244d99487919385aabc21337289457780beab27663b7fb3f639
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
34
|
-
|
35
|
-
|
36
|
-
|
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(:
|
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
|
54
|
-
|
55
|
-
|
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
|
-
|
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
data/lib/zgcp_toolkit/logger.rb
CHANGED
@@ -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
|
|
data/lib/zgcp_toolkit/version.rb
CHANGED
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:
|
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-
|
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
|