captive-log-utils 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 639c54a276ccc5432b4f8225d361c8fc5077616c605c2b891e52117340e91aff
4
+ data.tar.gz: 193d79f7d4369a5e3e5fcb8389e7cc12bdd7866d4d3556759771333502c6fb32
5
+ SHA512:
6
+ metadata.gz: 513bb7f21473119a6f6ade7a1bfb3f9f4b5a03f3f02249ec79878840550af9d50b48557b132bbe716b64b3a97e82e7c9d1d07c9ad08d55e4c0ba359ec18e0f1e
7
+ data.tar.gz: 6a5ac0095e215a310dba956a826fe475e60c46575de9c0ef7dc8c5e630a8ceaabc9351ee98eceacbadbd799b2235afdc8c2a915e0c59ed6ade9a4d9f695fa482
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Captive
4
+ module LogUtils
5
+ module Colors
6
+ PROCESS = {
7
+ "web" => "blue",
8
+ "worker" => "green",
9
+ "release" => "yellow",
10
+ "migrate" => "yellow",
11
+ "redis" => "red",
12
+ "db" => "magenta",
13
+ }.freeze
14
+
15
+ LEVEL = {
16
+ "error" => "red",
17
+ "fatal" => "red",
18
+ "warn" => "yellow",
19
+ "debug" => "dim",
20
+ }.freeze
21
+
22
+ def self.for_process(label)
23
+ PROCESS.fetch(label) do
24
+ PROCESS.values[label.sum % PROCESS.size]
25
+ end
26
+ end
27
+
28
+ def self.for_level(level)
29
+ LEVEL[level]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Captive
6
+ module LogUtils
7
+ module LogLevelDetector
8
+ def self.call(text)
9
+ json = JSON.parse(text)
10
+ level = (json["level"] || json["severity"] || "").downcase
11
+ case level
12
+ when /error|fatal/ then "error"
13
+ when /warn/ then "warn"
14
+ when /debug/ then "debug"
15
+ else "info"
16
+ end
17
+ rescue JSON::ParserError, TypeError
18
+ case text
19
+ when /\b(ERROR|FATAL)\b/i then "error"
20
+ when /\bWARN\b/i then "warn"
21
+ when /\bDEBUG\b/i then "debug"
22
+ else "info"
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Captive
4
+ module LogUtils
5
+ module ProcessLabel
6
+ POD_SUFFIX_RE = /-[a-z0-9]{5,10}-[a-z0-9]{5}\z/
7
+
8
+ # Dérive un label court depuis le nom du pod.
9
+ #
10
+ # container: quand fourni et différent de namespace, retourné tel quel
11
+ # (ex. "migrate", "release") — couvre le cas kubectl --prefix où le
12
+ # container name est explicite dans le préfixe [pod/<pod>/<container>].
13
+ def self.for(pod:, namespace:, container: nil)
14
+ return nil if pod.nil?
15
+ return container if container && container != namespace
16
+
17
+ return "db" if pod.match?(/\Apostgres-#{Regexp.escape(namespace)}-\d+\z/)
18
+
19
+ base = pod.sub(POD_SUFFIX_RE, "")
20
+ return "web" if base == namespace
21
+
22
+ label = base.delete_prefix("#{namespace}-")
23
+ label.match?(/\Aredis-\d+\z/) ? "redis" : label
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Captive
4
+ module LogUtils
5
+ VERSION = "0.2.0"
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "log_utils/version"
4
+ require_relative "log_utils/log_level_detector"
5
+ require_relative "log_utils/process_label"
6
+ require_relative "log_utils/colors"
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: captive-log-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Captive Studio
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - web@captive.fr
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - lib/captive/log_utils.rb
19
+ - lib/captive/log_utils/colors.rb
20
+ - lib/captive/log_utils/log_level_detector.rb
21
+ - lib/captive/log_utils/process_label.rb
22
+ - lib/captive/log_utils/version.rb
23
+ homepage: https://github.com/captive-studio/captive-log-utils
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '4.0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 4.0.10
42
+ specification_version: 4
43
+ summary: Utilitaires partagés pour le parsing et la classification des logs Kubernetes
44
+ test_files: []