ruby_for_grafana_loki 0.0.4 → 0.0.5

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: '008364bfc6b1bf0553546183972f87eb93794364317f2cc6a56b944c14a4deb8'
4
+ data.tar.gz: 00affa1f6564765b4ad1211e1c3efdae57e2e7c7202f9049e75c572772d237ec
5
5
  SHA512:
6
- metadata.gz: d5fccfd9c6a16fdfa7c710bcb3bd1a04c81343e6bcbccc4346530c45c62d269e50e26ab55ec126fce053d5dcfadad86fe11673c86f753593bdd84a5fce435a66
7
- data.tar.gz: 5400a75de89bdbc5df1daf9078079130a3c89c4d41ba6c93a7c23e059b949e09af7413331b45f697be566f9645c929b2e94d399ef58b8681cdb68a20aa1bf81a
6
+ metadata.gz: af9ed24b5ba9981b6cf927928779e33b8e0129a72280acdbc673f712cd33e4c3a98292204abaf7881897635e897b459d61ba024a98cee2a9e0d2df78ec1f3d3d
7
+ data.tar.gz: d67fd43f8db4dce356f9bbcf65c6da681b330b9d8ca140aea08ccf78a30b13875c00ce0655328c41bcb8f2bd00ab3c80d704e18ead795934235c09ffe02c15aa
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>
@@ -3,9 +3,16 @@ module RubyForGrafanaLoki
3
3
  class Client
4
4
  include RubyForGrafanaLoki::Request
5
5
 
6
+ attr_accessor :job_name
7
+ attr_accessor :host_name
8
+ attr_accessor :source_name
9
+
6
10
  def initialize(log_file_path, allowed_logs_type = LOGS_TYPE)
7
11
  @log_file_path = log_file_path
8
12
  @allowed_logs_type = allowed_logs_type
13
+ @job_name = "job_name"
14
+ @host_name = "host_name"
15
+ @source_name = "source_name"
9
16
  end
10
17
 
11
18
  def send_all_logs
@@ -15,25 +22,25 @@ module RubyForGrafanaLoki
15
22
  end
16
23
  end
17
24
  end
25
+
18
26
  def send_log(log_message)
19
27
  curr_datetime = Time.now.to_i * 1_000_000_000
20
28
 
21
- host = "somehost"
22
- msg = "On server #{host} detected error"
29
+ msg = "On server #{@host_name} detected error"
23
30
 
24
31
  payload = {
25
- "streams" => [
32
+ 'streams' => [
26
33
  {
27
- "stream" => {
28
- "source" => "Name-of-your-source",
29
- "job" => "name-of-your-job",
30
- "host" => host
34
+ 'stream' => {
35
+ 'source' => @source_name,
36
+ 'job' => @job_name,
37
+ 'host' => @host_name
31
38
  },
32
- "values" => [[curr_datetime.to_s, log_message]],
33
- "entries" => [
39
+ 'values' => [[curr_datetime.to_s, log_message]],
40
+ 'entries' => [
34
41
  {
35
- "ts" => curr_datetime,
36
- "line" => "[WARN] " + msg
42
+ 'ts' => curr_datetime,
43
+ 'line' => "[WARN] " + msg
37
44
  }
38
45
  ]
39
46
  }
@@ -1,3 +1,3 @@
1
1
  module RubyForGrafanaLoki
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Ten