logdna 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c55551804963d24df4eb0ea8582cce2043f0567d
4
- data.tar.gz: 0e9aa46f633cfa23ebc9d9d13ce1203be38a6e59
3
+ metadata.gz: 783a6b3016403a140faca9e0e097d5a3997b59b2
4
+ data.tar.gz: 1d67f778ded84e82f7047e292256eca6ee51ca92
5
5
  SHA512:
6
- metadata.gz: acd3e19e004f4b09a800558f2b82ed310fffedd2281829b6a7342492ff0fa403ac3ad4a9219797e44734d2da297b99546e1182bc74bce495cd11f541c91bc8f2
7
- data.tar.gz: d90c07c141bb8a0ad76fe035177349db15d7a332c9d91081731aee278db55e3ed1c6b3e284d717530595bb671801d48edae2656f44560b4982d20cb92952459b
6
+ metadata.gz: 1e6653f54721fc2d7bc28df9dd546c9e7d34008b7dbb01080ef06da1e4b2c968c60ce4837e34c3f5f7ebb8a3937cc020dc8b0f3712d0378af22f9ff180a910fa
7
+ data.tar.gz: ed2c73279b66651f8894b40eb9baa2abececab4a9d66197db5e39ec9112fbb4f9334cd324532744f28b69d4e7a0a64256f897f50b538faff039bed83f71765a9
data/README.md CHANGED
@@ -36,7 +36,7 @@ Or install it yourself as:
36
36
 
37
37
  After installation, call
38
38
 
39
- logger = Logdna::Ruby.new(your_ingestion_key, options)
39
+ logger = Logdna::Ruby.new(your_api_key, options)
40
40
  => #<Logdna::Ruby:0x00000000000000>
41
41
 
42
42
  to set up the logger.
@@ -48,45 +48,44 @@ Options are optional variables that may contain hostname, app name, mac address,
48
48
  :ip => myIpAddress,
49
49
  :mac => myMacAddress,
50
50
  :app => myAppName,
51
- :level => "INFO" # LOG_LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'] or your customized log level
52
- :env => "PRODUCTION"
51
+ :level => "INFO", # LOG_LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'] or your customized log level
52
+ :env => "PRODUCTION",
53
+ :meta => {:once => {:first => "nested1", :another => "nested2"}}
53
54
  }
54
55
 
55
-
56
- To send logs, use "log" method.
56
+ To send logs, use "log" method. Default log level is "INFO"
57
57
 
58
58
  logger.log('This is my first log')
59
59
  => "Saved" # Saved to buffer. Ready to be flushed automatically
60
60
 
61
+ Log a message with particular metadata, level, appname, environment (one-time)
61
62
 
62
- By default, it will log at the level of "INFO" unless you specified otherwise during the initialzation of the logger.
63
- You can change a particular message's log level.
64
-
65
- logger.log('This is warn message', {:level => "WARN"})
66
-
63
+ logger.log('This is warn message', {:meta => {:meta => "data"}, :level => "WARN", :app => "awesome", :env => "DEVELOPMENT"})
67
64
 
68
- You can also send a metadata with your message by specifying 'meta' field
69
-
70
- logger.log('This is a message with metadata', {:meta => {:once => {:first => "nested1", :another => "nested2"}}, :level => "TRACE"})
65
+ Log a message with lasting metadata, level, appname, environment (lasting)
71
66
 
67
+ logger.meta = {:once => {:first => "nested1", :another => "nested2"}}
68
+ logger.level = 'FATAL' or logger.level = Logger::FATAL
69
+ logger.app = 'NEW APP NAME'
70
+ logger.env = 'PRODUCTION'
71
+ logger.log('This messages and messages afterwards all have the above values')
72
72
 
73
- Hostname and app name cannot be more than 80 characters.
73
+ Clear current metadata, level, appname, environment
74
74
 
75
- This logger extends the standard Ruby logger and inherits some of the conventions from it.
75
+ logger.clear
76
76
 
77
- logger.info('This is info log') # same as logger.log('This is info message', {:level => "INFO"})
77
+ Check current log level:
78
+
78
79
  logger.info? => true
79
- logger.trace('trace log')
80
- logger.error('error log')
80
+ logger.warn? => false
81
81
 
82
- You can also set logger level, environment, app name this way:
82
+ Log a message with a particular level easily
83
83
 
84
- logger.env = 'PRODUCTION'
85
- logger.app = 'NEW APP NAME'
86
- logger.level = 'FATAL'
87
- logger.level = Logger::FATAL
84
+ logger.warn('This is a warning message')
85
+ logger.fatal('This is a fatal message')
88
86
 
89
87
 
88
+ Hostname and app name cannot be more than 80 characters.
90
89
 
91
90
 
92
91
  # Important Notes
@@ -109,6 +108,7 @@ Instantiates a new instance of the class it is called on. ingestion_key is requi
109
108
  |{ :app => App name } | 'default' |
110
109
  |{ :level => Log level } | 'INFO' |
111
110
  |{ :env => STAGING, PRODUCTION .. etc} | Nil |
111
+ |{ :meta => metadata} | Nil |
112
112
  |{ :flushtime => Log flush interval in seconds } | 0.25 seconds |
113
113
  |{ :flushbyte => Log flush upper limit in bytes } | 500000 bytes ~= 0.5 megabytes |
114
114
 
@@ -6,10 +6,11 @@ require_relative 'logdna/resources.rb'
6
6
  module Logdna
7
7
  class Ruby < ::Logger
8
8
  Logger::TRACE = 5
9
- attr_accessor :level, :app, :env
9
+ attr_accessor :level, :app, :env, :meta
10
10
  @level = nil
11
11
  @app = nil
12
12
  @env = nil
13
+ @meta = nil
13
14
 
14
15
  def initialize(key, opts={})
15
16
  @@client = Logdna::Client.new(key, opts)
@@ -23,14 +24,8 @@ module Logdna
23
24
  end
24
25
 
25
26
  def log(msg=nil, opts={})
26
- if @level || @app || @env
27
- @@client.change(@level, @app, @env)
28
- @level = nil
29
- @app = nil
30
- @env = nil
31
- end
32
-
33
27
  loggerExist?
28
+ optionChanged?
34
29
  @response = @@client.tobuffer(msg, opts)
35
30
  'Saved'
36
31
  end
@@ -38,6 +33,7 @@ module Logdna
38
33
  def trace(msg=nil, opts={})
39
34
  opts[:level] = "TRACE"
40
35
  loggerExist?
36
+ optionChanged?
41
37
  @response = @@client.tobuffer(msg, opts)
42
38
  'Saved'
43
39
  end
@@ -45,6 +41,7 @@ module Logdna
45
41
  def debug(msg=nil, opts={})
46
42
  opts[:level] = "DEBUG"
47
43
  loggerExist?
44
+ optionChanged?
48
45
  @response = @@client.tobuffer(msg, opts)
49
46
  'Saved'
50
47
  end
@@ -52,6 +49,7 @@ module Logdna
52
49
  def info(msg=nil, opts={})
53
50
  opts[:level] = "INFO"
54
51
  loggerExist?
52
+ optionChanged?
55
53
  @response = @@client.tobuffer(msg, opts)
56
54
  'Saved'
57
55
  end
@@ -59,6 +57,7 @@ module Logdna
59
57
  def warn(msg=nil, opts={})
60
58
  opts[:level] = "WARN"
61
59
  loggerExist?
60
+ optionChanged?
62
61
  @response = @@client.tobuffer(msg, opts)
63
62
  'Saved'
64
63
  end
@@ -66,6 +65,7 @@ module Logdna
66
65
  def error(msg=nil, opts={})
67
66
  opts[:level] = "ERROR"
68
67
  loggerExist?
68
+ optionChanged?
69
69
  @response = @@client.tobuffer(msg, opts)
70
70
  'Saved'
71
71
  end
@@ -73,6 +73,7 @@ module Logdna
73
73
  def fatal(msg=nil, opts={})
74
74
  opts[:level] = "FATAL"
75
75
  loggerExist?
76
+ optionChanged?
76
77
  @response = @@client.tobuffer(msg, opts)
77
78
  'Saved'
78
79
  end
@@ -125,6 +126,16 @@ module Logdna
125
126
  logLevel('FATAL')
126
127
  end
127
128
 
129
+ def clear
130
+ loggerExist?
131
+ @@client.clear()
132
+ @level = nil
133
+ @app = nil
134
+ @env = nil
135
+ @meta = nil
136
+ return true
137
+ end
138
+
128
139
  def loggerExist?
129
140
  if @@client.nil?
130
141
  puts "Logger Not Initialized Yet"
@@ -132,6 +143,16 @@ module Logdna
132
143
  end
133
144
  end
134
145
 
146
+ def optionChanged?
147
+ if @level || @app || @env || @meta
148
+ @@client.change(@level, @app, @env, @meta)
149
+ @level = nil
150
+ @app = nil
151
+ @env = nil
152
+ @meta = nil
153
+ end
154
+ end
155
+
135
156
  def logLevel(comparedTo)
136
157
  if @level.is_a? Numeric
137
158
  @level = Resources::LOG_LEVELS[@level]
@@ -142,6 +163,7 @@ module Logdna
142
163
  def <<(msg=nil, opts={})
143
164
  opts[:level] = ""
144
165
  loggerExist?
166
+ optionChanged?
145
167
  @response = @@client.tobuffer(msg, opts)
146
168
  'Saved'
147
169
  end
@@ -154,6 +176,7 @@ module Logdna
154
176
  def unknown(msg=nil, opts={})
155
177
  opts[:level] = "UNKNOWN"
156
178
  loggerExist?
179
+ optionChanged?
157
180
  @response = @@client.tobuffer(msg, opts)
158
181
  'Saved'
159
182
  end
@@ -18,7 +18,8 @@ module Logdna
18
18
  :mac => opts.key?(:mac) ? "&mac=#{opts[:mac]}" : "",
19
19
  :app => (opts[:app] ||= "default"),
20
20
  :level => (opts[:level] ||= "INFO"),
21
- :env => (opts[:env])
21
+ :env => (opts[:env]),
22
+ :meta => (opts[:meta])
22
23
  }.reject { |k,v| k === :env && v.nil? }
23
24
 
24
25
  begin
@@ -54,7 +55,7 @@ module Logdna
54
55
  end
55
56
  end
56
57
 
57
- def change(level, app, env)
58
+ def change(level, app, env, meta)
58
59
  if level
59
60
  if level.is_a? Numeric
60
61
  level = Resources::LOG_LEVELS[level]
@@ -67,6 +68,16 @@ module Logdna
67
68
  if env
68
69
  @qs[:env] = env
69
70
  end
71
+ if meta
72
+ @qs[:meta] = meta
73
+ end
74
+ end
75
+
76
+ def clear()
77
+ @qs[:level] = "INFO"
78
+ @qs[:app] = "default"
79
+ @qs[:env] = nil
80
+ @qs[:meta] = nil
70
81
  end
71
82
 
72
83
  def getLevel
@@ -101,8 +112,8 @@ module Logdna
101
112
  :app => opts[:app] ||= @qs[:app],
102
113
  :level => opts[:level] ||= @qs[:level],
103
114
  :timestamp => Time.now.to_i,
104
- :meta => opts[:meta] ||= nil,
105
- :env => (opts[:env]) ? opts[:env] : (@qs[:env]) ? @qs[:env] : nil
115
+ :meta => (opts[:meta]) ? opts[:meta] : (@qs[:meta]) ? @qs[:meta] : nil,
116
+ :env => (opts[:env]) ? opts[:env] : (@qs[:env]) ? @qs[:env] : nil,
106
117
  }.reject { |k,v| k === :meta && v.nil? })
107
118
  else
108
119
  @secondbytesize += msg.bytesize
@@ -111,8 +122,8 @@ module Logdna
111
122
  :app => opts[:app] ||= @qs[:app],
112
123
  :level => opts[:level] ||= @qs[:level],
113
124
  :timestamp => Time.now.to_i,
114
- :meta => opts[:meta] ||= nil,
115
- :env => (opts[:env]) ? opts[:env] : (@qs[:env]) ? @qs[:env] : nil
125
+ :meta => (opts[:meta]) ? opts[:meta] : (@qs[:meta]) ? @qs[:meta] : nil,
126
+ :env => (opts[:env]) ? opts[:env] : (@qs[:env]) ? @qs[:env] : nil,
116
127
  }.reject { |k,v| k === :meta && v.nil? })
117
128
  end
118
129
 
@@ -1,3 +1,3 @@
1
1
  module LogDNA
2
- VERSION = '1.0.8'.freeze
2
+ VERSION = '1.0.9'.freeze
3
3
  end
data/test.rb CHANGED
@@ -2,13 +2,40 @@ require 'require_all'
2
2
  require_all 'lib'
3
3
 
4
4
 
5
- options = {hostname: "new"}
5
+ options = {hostname: "new", meta:{:once => {:first => "nested1", :another => "nested2"}}}
6
6
 
7
7
 
8
- logger1 = Logdna::Ruby.new('Your API Key', options)
8
+ logger1 = Logdna::Ruby.new('You API KEY', options)
9
+
10
+ logger1.log('This is the start of test')
11
+ logger1.env = 'STAGING'
12
+ logger1.app = 'HELLO'
13
+ logger1.warn('Warn message with Staging and Hello')
14
+ logger1.clear
15
+ logger1.log('Is everything back to normal?')
16
+
17
+
18
+ logger1.log('Testing env app name change using log')
19
+ logger1.env = 'PRODUCTION'
20
+ logger1.app = 'CHANGED'
21
+ logger1.log('This should be stage = PRODUCTION and appname = CHANGED')
22
+ logger1.log('Testing env app name change using other messages')
23
+
24
+
25
+ logger1.error('This is error message with env = DEVELOPMENT and appname = NIHAO', {:env => 'DEVELOPMENT', :app => 'NIHAO'})
26
+ logger1.log('Should not stay as DEVELOPMENT and NIHAO')
27
+ logger1.env = 'DEVELOPMENT'
28
+ logger1.app = 'NIHAO'
29
+ logger1.log('Now should be DEVELOPMENT and NIHAO')
30
+ logger1.log('Logging metadata in trace level', {:meta => {:once => {:first => "nested1", :another => "nested2"}}, :level => "TRACE"})
31
+
32
+
33
+ logger1.level = Logger::DEBUG
34
+ logger1.log('This is debug message')
35
+ logger1.add('this should not be supported')
36
+ logger1.fatal('Does this continue as fatal?')
37
+ logger1.log('This should be debug')
9
38
 
10
- logger1.level = Logger::TRACE
11
- logger1.log('is this trace')
12
39
 
13
40
  =begin
14
41
  logger1.level = Logger::WARN
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logdna
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gun Woo Choi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-15 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby