logatron 0.2.5 → 0.2.6

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: 996a82f534fa1a3877a7e06053872b349ebbb4e5
4
- data.tar.gz: 7c9c7e45c9c117a92b3a29e58ab62da46a108725
3
+ metadata.gz: c0d3fc64e66b4cdc0f85cdd1dd9124edb59a77ce
4
+ data.tar.gz: d0cc1924c4c28c1a475224e3146710635d7fb0a0
5
5
  SHA512:
6
- metadata.gz: d16b54849df41e7d97b11888acdfafede8d0a11b73f1c7a70f5a3cc9c06202b412e1d0d016c312dc64612b36095b1a7a2483aa268c4badce4c17c9d5535c2304
7
- data.tar.gz: caba7a2dfc16ecc7be6e5da47896fbce5c9911cf7f345962674d2e2ebd9f6b94f1017e99fa8b6eea2e8d37008ec2ebc7e1b090b22fbd76638e2933262509d18d
6
+ metadata.gz: adea0b753a1eb719124166d3aadc7b507054cd971c3873c62ffc9b7464b922ea105cf01348cab27ae7b5da57ac36e324517695c4d5440e9304b9c02052e8f2b1
7
+ data.tar.gz: 64d1ee8c85bc03a8dfb056758d429f3a793d65a22ec94427f5940547c33bb5fba84e676c0760b62344cbfa8adbc603808896f7dce120bbd67288a47ee0b05c34
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- logatron (0.2.5)
4
+ logatron (0.2.6)
5
5
  activesupport (~> 4.2, >= 4.2.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (4.2.5)
10
+ activesupport (4.2.5.1)
11
11
  i18n (~> 0.7)
12
12
  json (~> 1.7, >= 1.7.7)
13
13
  minitest (~> 5.1)
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # Logatron
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/logatron/logatron`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
@@ -26,13 +22,15 @@ Or install it yourself as:
26
22
  Severities are used to examine and filter server logs, create alerts, and analyze user behavior.
27
23
 
28
24
  * Debug - use for fixing production bugs or deeper inspection into behavior
29
- * Invalid Use - use for user errors due to invalid inputs
30
25
  * Info - use for general information (successful operations, ec.)
26
+ * Invalid Use - use for user errors due to invalid inputs
31
27
  * Warn - use for recoverable errors
32
28
  * Error - use for known unrecoverable errors
33
29
  * Critical - use for unknown unrecoverable errors (system-level rescues)
34
30
  * Fatal - use for system errors
35
31
 
32
+ *Invalid Use* - inappropriate inputs from a user - are not immediately actionable for a development team, but may provide input into customer care, future features, or bug fixes for poorly implemented features. This makes them a discrete category similar to `INFO` so that any queries on the logs can be readily consumed by such information seekers.
33
+
36
34
  ## Development
37
35
 
38
36
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -22,6 +22,10 @@ module Logatron
22
22
  write(format_log(msg: msg, severity: DEBUG), SEVERITY_MAP[DEBUG])
23
23
  end
24
24
 
25
+ def invalid_use(msg)
26
+ write(format_log(msg: msg, severity: INVALID_USE), SEVERITY_MAP[INVALID_USE])
27
+ end
28
+
25
29
  def error(msg)
26
30
  write(format_log(msg: msg, severity: ERROR), SEVERITY_MAP[ERROR])
27
31
  end
@@ -39,16 +43,16 @@ module Logatron
39
43
  start = Time.now
40
44
  begin
41
45
  res = block.call(ml)
42
- write(format_log(severity: severity, msg: msg, status: status, duration: milliseconds_elapsed(Time.now, start), inputs: source, request: request),SEVERITY_MAP[severity])
46
+ write(format_log(severity: severity, msg: msg, status: status, duration: milliseconds_elapsed(Time.now, start), inputs: source, request: request), SEVERITY_MAP[severity])
43
47
  res
44
48
  rescue Exception => e
45
- write(format_log(severity: severity, msg: msg, status: status, duration: milliseconds_elapsed(Time.now, start), inputs: source, request: request),SEVERITY_MAP[severity])
49
+ write(format_log(severity: severity, msg: msg, status: status, duration: milliseconds_elapsed(Time.now, start), inputs: source, request: request), SEVERITY_MAP[severity])
46
50
  ml.flush
47
51
  raise e
48
52
  end
49
53
  end
50
54
 
51
- def write(string,severity)
55
+ def write(string, severity)
52
56
  Logatron.configuration.logger.log(severity, string)
53
57
  end
54
58
  end
@@ -9,14 +9,7 @@ module Logatron
9
9
 
10
10
  def initialize(logger)
11
11
  @logger = logger
12
- @logs = {
13
- DEBUG => [],
14
- INFO => [],
15
- WARN => [],
16
- ERROR => [],
17
- CRITICAL => [],
18
- FATAL => []
19
- }
12
+ @logs = Hash[Logatron::SEVERITY_MAP.keys.map{|key| [key, []]}]
20
13
  end
21
14
 
22
15
  def info(msg)
@@ -31,6 +24,10 @@ module Logatron
31
24
  write(format_log(msg: msg, severity: DEBUG), DEBUG)
32
25
  end
33
26
 
27
+ def invalid_use(msg)
28
+ write(format_log(msg: msg, severity: INVALID_USE), INVALID_USE)
29
+ end
30
+
34
31
  def error(msg)
35
32
  write(format_log(msg: msg, severity: ERROR), ERROR)
36
33
  end
@@ -50,10 +47,9 @@ module Logatron
50
47
  def flush
51
48
  Logatron.configuration.loggable_levels.each do |key|
52
49
  @logs[key].each do |item|
53
- @logger.write(item,SEVERITY_MAP[key])
50
+ @logger.write(item, SEVERITY_MAP[key])
54
51
  end
55
52
  end
56
53
  end
57
54
  end
58
-
59
55
  end
@@ -30,13 +30,9 @@ module Logatron
30
30
  @transformer = proc {|x| x.to_json}
31
31
  @host = `hostname`.chomp
32
32
  @level = INFO
33
- levels = [DEBUG,
34
- INFO,
35
- WARN,
36
- ERROR,
37
- CRITICAL,
38
- FATAL]
39
- @loggable_levels = levels.slice(levels.index(@level), levels.size-1)
33
+ level_threshold = SEVERITY_MAP[@level]
34
+ levels = Logatron::SEVERITY_MAP.keys
35
+ @loggable_levels = levels.select{|level| SEVERITY_MAP[level] >= level_threshold}
40
36
  bc = ActiveSupport::BacktraceCleaner.new
41
37
  bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } if defined? Rails
42
38
  bc.add_silencer { |line| line =~ /gems/ }
@@ -1,20 +1,31 @@
1
1
  module Logatron
2
- WARN = 'WARN'.freeze
2
+ MSG_ID = :msg_id
3
+ SITE = :site
4
+
5
+ DEBUG = 'DEBUG'.freeze
6
+ INVALID_USE = 'INVALID_USE'.freeze
3
7
  INFO = 'INFO'.freeze
8
+ WARN = 'WARN'.freeze
4
9
  ERROR = 'ERROR'.freeze
5
10
  CRITICAL = 'CRITICAL'.freeze
6
11
  FATAL = 'FATAL'.freeze
7
- DEBUG = 'DEBUG'.freeze
8
- INVALID_USE = 'INVALID_USE'.freeze
9
- MSG_ID = :msg_id
10
- SITE = :site
12
+
13
+ # Maps Constants to the Logger Severity Integers:
14
+ # DEBUG = 0
15
+ # INFO = 1
16
+ # WARN = 2
17
+ # ERROR = 3
18
+ # FATAL = 4
19
+ # UNKNOWN = 5
20
+ # Note that the Logatron Severities will be put into
21
+ # the logs (severity => INVALID_USE), for filtering purposes
11
22
  SEVERITY_MAP = {
12
23
  Logatron::DEBUG => 0,
24
+ Logatron::INFO => 1,
13
25
  Logatron::INVALID_USE => 1,
14
- Logatron::INFO => 2,
15
- Logatron::WARN => 3,
16
- Logatron::ERROR => 4,
17
- Logatron::CRITICAL => 5,
18
- Logatron::FATAL => 6
26
+ Logatron::WARN => 2,
27
+ Logatron::ERROR => 3,
28
+ Logatron::CRITICAL => 4,
29
+ Logatron::FATAL => 5
19
30
  }
20
31
  end
@@ -7,18 +7,17 @@ module Logatron
7
7
  end
8
8
 
9
9
  def format_log(msg: '-', status: '-', duration: '-', request: '-', inputs: '-', severity: '-')
10
- Logatron.configuration.transformer.call({
11
- timestamp: Time.now.iso8601,
12
- severity: severity,
13
- host: Logatron.configuration.host,
14
- id: Contexts.msg_id,
15
- site: Contexts.site,
16
- status: status,
17
- duration: duration,
18
- request: request,
19
- source: inputs,
20
- body: msg
21
- }) + "\n"
10
+ Logatron.configuration.transformer.call(
11
+ timestamp: Time.now.iso8601,
12
+ severity: severity,
13
+ host: Logatron.configuration.host,
14
+ id: Contexts.msg_id,
15
+ site: Contexts.site,
16
+ status: status,
17
+ duration: duration,
18
+ request: request,
19
+ source: inputs,
20
+ body: msg) + "\n"
22
21
  end
23
22
  end
24
23
  end
data/logatron.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'logatron/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'logatron'
8
- spec.version = '0.2.5'
8
+ spec.version = '0.2.6'
9
9
  spec.authors = ['Justin Grimes']
10
10
  spec.email = ['justin.mgrimes@gmail.com']
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Grimes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport