ruby_for_grafana_loki 0.0.4 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50f0f3f252b03e126ca79c758b0ec428942695733470126f9d70a1f4d9d817b1
4
- data.tar.gz: 4bf5183f13b98110611e0767d2cb196c70ac2bb9a92f7711b36e90df71519087
3
+ metadata.gz: 585c4f7f187bc40f31942698a8f46c0dd4ed0939ca47c4e692d5ed53b3e712cc
4
+ data.tar.gz: 29ce38884eb75cc9046b55767256eb999cafc6585606df8de8b620a0962ee891
5
5
  SHA512:
6
- metadata.gz: d5fccfd9c6a16fdfa7c710bcb3bd1a04c81343e6bcbccc4346530c45c62d269e50e26ab55ec126fce053d5dcfadad86fe11673c86f753593bdd84a5fce435a66
7
- data.tar.gz: 5400a75de89bdbc5df1daf9078079130a3c89c4d41ba6c93a7c23e059b949e09af7413331b45f697be566f9645c929b2e94d399ef58b8681cdb68a20aa1bf81a
6
+ metadata.gz: 00ea45cbd679c2a9c5388f5935b03eb7b61bf7b8a92c06e5c8d653d854da9b71803837dd91721a5fc9455e81c33607e8a661b55ac9678fdd571bd70d8bf13258
7
+ data.tar.gz: 9beda2ef7e96973cda525d86378213f0d92584596c920e99985779a1e14acc74852a8a33b89fd90204082b490fcf554d59a6d52c7eaf89832f7140ddeb3e2d7e
data/README.md CHANGED
@@ -1,11 +1,18 @@
1
1
 
2
2
  # Usage in your gem or application
3
3
  <pre>
4
+
5
+ - add gem "ruby_for_grafana_loki-0.0.5.gem" //to the Gemfile
6
+ - bundle install
7
+
8
+ in the project:
9
+ - logs_type = %w(ERROR WARN FATAL) // Use custom logs type: ERROR, WARN, FATAL, INFO, DEBUG
10
+ - log_file_path = "log/#{Rails.env}.log"
11
+ - client = RubyForGrafanaLoki.client(log_file_path, logs_type)
12
+ - client.jobName = "job name" // your job name
13
+ - client.hostName = "host name" // your host name
14
+ - client.sourceName = "source name" // your source name
15
+ - client.send_all_logs
16
+ - client.send_log("This is a test log message.")
4
17
 
5
-
6
- logs_type = %w(ERROR WARN) # Use custom logs type: ERROR, WARN, FATAL, INFO, DEBUG
7
- log_file_path = "log/#{Rails.env}.log"
8
- client = RubyForGrafanaLoki.client(log_file_path, logs_type)
9
- client.send_all_logs
10
- client.send_log("This is a log message.") # not required
11
18
  </pre>
@@ -1,11 +1,19 @@
1
1
  module RubyForGrafanaLoki
2
2
  LOGS_TYPE = %w(ERROR WARN FATAL INFO DEBUG).freeze
3
+
3
4
  class Client
4
5
  include RubyForGrafanaLoki::Request
5
6
 
7
+ attr_accessor :job_name
8
+ attr_accessor :host_name
9
+ attr_accessor :source_name
10
+
6
11
  def initialize(log_file_path, allowed_logs_type = LOGS_TYPE)
7
12
  @log_file_path = log_file_path
8
13
  @allowed_logs_type = allowed_logs_type
14
+ @job_name = "job name"
15
+ @host_name = "host name"
16
+ @source_name = "source name"
9
17
  end
10
18
 
11
19
  def send_all_logs
@@ -15,25 +23,25 @@ module RubyForGrafanaLoki
15
23
  end
16
24
  end
17
25
  end
26
+
18
27
  def send_log(log_message)
19
28
  curr_datetime = Time.now.to_i * 1_000_000_000
20
29
 
21
- host = "somehost"
22
- msg = "On server #{host} detected error"
30
+ msg = "On server #{@host_name} detected error"
23
31
 
24
32
  payload = {
25
- "streams" => [
33
+ 'streams' => [
26
34
  {
27
- "stream" => {
28
- "source" => "Name-of-your-source",
29
- "job" => "name-of-your-job",
30
- "host" => host
35
+ 'stream' => {
36
+ 'source' => @source_name,
37
+ 'job' => @job_name,
38
+ 'host' => @host_name
31
39
  },
32
- "values" => [[curr_datetime.to_s, log_message]],
33
- "entries" => [
40
+ 'values' => [[curr_datetime.to_s, log_message]],
41
+ 'entries' => [
34
42
  {
35
- "ts" => curr_datetime,
36
- "line" => "[WARN] " + msg
43
+ 'ts' => curr_datetime,
44
+ 'line' => "[WARN] " + msg
37
45
  }
38
46
  ]
39
47
  }
@@ -46,8 +54,6 @@ module RubyForGrafanaLoki
46
54
  post(uri, json_payload)
47
55
  end
48
56
 
49
- private
50
-
51
57
  def match_logs_type?(log_line)
52
58
  type = log_line.match(/(ERROR|WARN|FATAL|INFO|DEBUG)/)&.to_s
53
59
 
@@ -18,7 +18,7 @@ module RubyForGrafanaLoki
18
18
 
19
19
  # Check if the request was successful
20
20
  if response.success?
21
- return JSON.parse(response.body)
21
+ JSON.parse(response.body)
22
22
  else
23
23
  raise "Failed to make POST request. Response code: #{response.status}, Response body: #{response.body}"
24
24
  end
@@ -30,7 +30,7 @@ module RubyForGrafanaLoki
30
30
  accept: 'application/json',
31
31
  'Content-Type' => 'application/json'
32
32
  }
33
- return {
33
+ {
34
34
  url: BASE_URL,
35
35
  headers: headers
36
36
  }
@@ -1,3 +1,3 @@
1
1
  module RubyForGrafanaLoki
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_for_grafana_loki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Ten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-06 00:00:00.000000000 Z
11
+ date: 2023-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Attempt to make gem
55
+ description: Send logs to Grafana Loki
56
56
  email:
57
57
  - tennet0505@gmail.com
58
58
  executables: []