logdna 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: d025f71abf5afb886b942d4092c6e902dbf88ee8
4
- data.tar.gz: 4748c857fec602e2b4e56217e6f6d908bc99c84a
3
+ metadata.gz: 4f23d7547c0ad450d24da026d2372b7955d457d1
4
+ data.tar.gz: abd18f8b965a7fd617041d0f0315240a6d948567
5
5
  SHA512:
6
- metadata.gz: fe6bba13754c9a64124a2a56401b76a08bcdd97d48fa5e8f62c6808f558fc1c99bc46d821ad78c2506b7482d7b744256c36036420802cf87cac424891fe8e38b
7
- data.tar.gz: 486b11af0975e3a5543b1792b06d169fc4938f2005f6ec28071b42fcdfb7aa69e48235379a31ab8f91007d9e4283ff550c2dffed0f7e3cb4302018215f35d277
6
+ metadata.gz: 7cf8461aaa9e54b156ee7d7546415c1d5207262d481b885a9fa6c01b7610b9e7a3d945709d7cf07dfa3e5425f6374598d8558db88952804dbb6c04c8bd83b34b
7
+ data.tar.gz: faf14c530c39d75ebdfdcec9b928de573b820e138f7c2c38769c1bb420d32471bc6723a287aa1b4ba458c4dcf07997ba417db8070f1756d6ba2ddff71dc5dc69
data/README.md CHANGED
@@ -46,6 +46,8 @@ Options:
46
46
  * logdev: The log device. This is a filename (String) or IO object (e.g. STDOUT, STDERR, an open file). Default: STDOUT.
47
47
  * shift_age: Number of old log files to keep, or frequency of rotation (daily, weekly, or monthly). Default: 7.
48
48
  * shift_size: Maximum logfile size (only applies when shift_age is a number). Default: 1,048,576
49
+ * buffer_max_size: Maximum number of lines in buffer.
50
+ * buffer_timeout: Frequency of posting requests to LogDNA.
49
51
  * mac: MAC address. Default: nil.
50
52
  * ip: IP address. Default: nil.
51
53
 
data/lib/logdna.rb CHANGED
@@ -22,7 +22,7 @@ module LogDNA
22
22
  super
23
23
  return true if severity < @level
24
24
  message ||= yield
25
- post_to_logdna(message, severity, progname) if @open
25
+ push_to_buffer(message, severity, progname) if @open
26
26
  end
27
27
 
28
28
  def close_http
@@ -54,20 +54,25 @@ module LogDNA
54
54
  @host = hostname.to_s
55
55
  @mac = opts[:mac].to_s
56
56
  @ip = opts[:ip].to_s
57
+ @buffer = []
58
+ @buffer_max = opts[:buffer_max_size] || 10
59
+ @freq = opts[:buffer_timeout] || 10
60
+ @last_posted = Time.now
57
61
  @open = true
58
62
  end
59
63
 
60
- def post_to_logdna(message, level = nil, source = 'none')
64
+ def post
65
+ @last_posted = Time.now
61
66
  res = @conn.headers(apikey: @api_key, 'Content-Type' => 'application/json')
62
67
  .post("/logs/ingest?hostname=#{@host}&mac=#{@mac}&ip=#{@ip}",
63
- json: request_body(message, level, source))
68
+ json: { e: 'ls', ls: @buffer })
64
69
  res.flush
65
70
  end
66
71
 
67
- def request_body(message, level, source)
68
- body = { e: 'line', line: message, timestamp: Time.now.to_i }
69
- body[:level] = LEVELS[level] if level
70
- body[:app] = source if source
71
- body
72
+ def push_to_buffer(message, level = nil, source = 'none')
73
+ line = { line: message, app: source, timestamp: Time.now.to_i }
74
+ line[:level] = LEVELS[level] if level
75
+ @buffer << line
76
+ post if @buffer.size > @buffer_max || Time.now - @last_posted > @freq
72
77
  end
73
78
  end
@@ -14,7 +14,7 @@ module LogDNA
14
14
 
15
15
  def <<(msg)
16
16
  super
17
- post_to_logdna(msg)
17
+ push_to_buffer(msg)
18
18
  end
19
19
  end
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module LogDNA
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logdna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - edwin-lai