logdna 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/README.md +43 -6
- data/lib/logdna.rb +18 -4
- data/lib/logdna/ruby_logger.rb +3 -0
- data/lib/logdna/version.rb +1 -1
- data/logdna.gemspec +3 -3
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24d909c4d53e174a268e19648d08d0b801890dbd
|
4
|
+
data.tar.gz: 35f91c6fb570116ade6040bb87ff5181ca18c1e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d833865aae127d9456c015f766240bfb016d15ca475089d3bec02b939c681a19ee7970b089429f24e06e8434aaf177e29290662823b0f8029782cbaa34b2857e
|
7
|
+
data.tar.gz: b5177cee5a3515c8862f8c065706f6d8889e5794b084212b107bcff7834de4336a11f5a265bbbd1974098db5311b4b9cd881555e7c71663d7995df60ef27c57d
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -34,6 +34,38 @@ Or install it yourself as:
|
|
34
34
|
|
35
35
|
$ gem install logdna
|
36
36
|
|
37
|
+
# Quick Setup
|
38
|
+
|
39
|
+
After installation, call
|
40
|
+
|
41
|
+
logger = LogDNA::RubyLogger.new(your_api_key, hostname)
|
42
|
+
|
43
|
+
to set up the logger.
|
44
|
+
|
45
|
+
To send logs, use exactly like the logger from the Ruby standard library. For example:
|
46
|
+
|
47
|
+
require 'logdna'
|
48
|
+
|
49
|
+
logger = LogDNA::RubyLogger.new(your_api_key, hostname)
|
50
|
+
logger.level = Logger::WARN
|
51
|
+
|
52
|
+
logger.debug("Created logger")
|
53
|
+
logger.info("Program started")
|
54
|
+
logger.warn("Nothing to do!")
|
55
|
+
|
56
|
+
path = "a_non_existent_file"
|
57
|
+
|
58
|
+
begin
|
59
|
+
File.foreach(path) do |line|
|
60
|
+
unless line =~ /^(\w+) = (.*)$/
|
61
|
+
logger.error("Line in wrong format: #{line.chomp}")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
rescue => err
|
65
|
+
logger.fatal("Caught exception; exiting")
|
66
|
+
logger.fatal(err)
|
67
|
+
end
|
68
|
+
|
37
69
|
# API
|
38
70
|
|
39
71
|
## ::new(api_key, hostname, options = {})
|
@@ -42,14 +74,19 @@ Instantiates a new instance of the class it is called on. api_key and hostname a
|
|
42
74
|
|
43
75
|
Options:
|
44
76
|
* logdev: The log device. This is a filename (String) or IO object (e.g. STDOUT, STDERR, an open file). Default: STDOUT.
|
45
|
-
* shift_age: Number of old log files to keep, or frequency of rotation (daily, weekly, or monthly). Default: 7.
|
46
|
-
* shift_size: Maximum logfile size (only applies when shift_age is a number). Default: 1,048,576
|
47
|
-
* buffer_max_size: Maximum number of lines in buffer.
|
48
|
-
* buffer_timeout: Frequency of posting requests to LogDNA.
|
49
77
|
* mac: MAC address. Default: nil.
|
50
78
|
* ip: IP address. Default: nil.
|
79
|
+
* default_app: Set a default app for this instance of the logger. Note that this can be overwritten by the progname below on the line level, as the app is a line attribute.
|
80
|
+
* environment: Alias for default_app.
|
81
|
+
|
82
|
+
__Make sure that the following options are numbers if you supply them. We are not responsible for any type errors if you enter non-numerical values for these options.__
|
83
|
+
|
84
|
+
* shift_age: Number of old log files to keep, or frequency of rotation (daily, weekly, or monthly). Default: 7.
|
85
|
+
* shift_size: Maximum logfile size (only applies when shift_age is a number). Default: 1,048,576
|
86
|
+
* buffer_max_size: Maximum number of lines in buffer. Default: 10
|
87
|
+
* buffer_timeout: Frequency of posting requests to LogDNA. Default: 10 (seconds)
|
51
88
|
|
52
|
-
## \#add
|
89
|
+
## \#add(severity, message=nil, progname=nil) {...}
|
53
90
|
|
54
91
|
Log a message if the given severity is high enough and post it to the LogDNA ingester. This is the generic logging method. Users will be more inclined to use debug, info, warn, error, and fatal (which all call \#add), as [described in the Ruby Logger documentation](https://ruby-doc.org/stdlib-2.3.0/libdoc/logger/rdoc/Logger.html). Note that these methods take a source as the argument and a block which returns a message. It returns the http response.
|
55
92
|
|
@@ -59,7 +96,7 @@ Close the HTTP connection to LogDNA's ingester.
|
|
59
96
|
|
60
97
|
## \#reopen_http
|
61
98
|
|
62
|
-
Open another HTTP connection to LogDNA's ingester if the connection is
|
99
|
+
Open another HTTP connection to LogDNA's ingester if the connection is already closed.
|
63
100
|
|
64
101
|
## \#<<(message)
|
65
102
|
|
data/lib/logdna.rb
CHANGED
@@ -35,6 +35,14 @@ module LogDNA
|
|
35
35
|
@open = true
|
36
36
|
end
|
37
37
|
|
38
|
+
def environment
|
39
|
+
@default_app
|
40
|
+
end
|
41
|
+
|
42
|
+
def environment=(env)
|
43
|
+
@default_app = env
|
44
|
+
end
|
45
|
+
|
38
46
|
private
|
39
47
|
|
40
48
|
def fill_opts_with_defaults(opts)
|
@@ -42,6 +50,10 @@ module LogDNA
|
|
42
50
|
opts[:logdev] ||= STDOUT
|
43
51
|
opts[:shift_age] ||= 7
|
44
52
|
opts[:shift_size] ||= 1_048_576
|
53
|
+
opts[:environment] ||= nil # alias for :default_app
|
54
|
+
opts[:default_app] ||= opts[:environment]
|
55
|
+
opts[:buffer_max_size] ||= 10
|
56
|
+
opts[:buffer_timeout] ||= 10
|
45
57
|
opts
|
46
58
|
end
|
47
59
|
|
@@ -51,9 +63,10 @@ module LogDNA
|
|
51
63
|
@host = hostname.to_s
|
52
64
|
@mac = opts[:mac].to_s
|
53
65
|
@ip = opts[:ip].to_s
|
66
|
+
@default_app = opts[:default_app] || 'none'
|
54
67
|
@buffer = []
|
55
|
-
@buffer_max = opts[:buffer_max_size]
|
56
|
-
@freq = opts[:buffer_timeout]
|
68
|
+
@buffer_max = opts[:buffer_max_size]
|
69
|
+
@freq = opts[:buffer_timeout]
|
57
70
|
@open = true
|
58
71
|
end
|
59
72
|
|
@@ -65,8 +78,9 @@ module LogDNA
|
|
65
78
|
res.flush
|
66
79
|
end
|
67
80
|
|
68
|
-
def push_to_buffer(message, level = nil, source =
|
69
|
-
|
81
|
+
def push_to_buffer(message, level = nil, source = nil)
|
82
|
+
app = source || @default_app
|
83
|
+
line = { line: message, app: app, timestamp: Time.now.to_i }
|
70
84
|
line[:level] = LEVELS[level] if level
|
71
85
|
start_timer if @buffer.empty?
|
72
86
|
@buffer << line
|
data/lib/logdna/ruby_logger.rb
CHANGED
@@ -5,6 +5,9 @@ module LogDNA
|
|
5
5
|
class RubyLogger < ::Logger
|
6
6
|
include LogDNA
|
7
7
|
|
8
|
+
attr_reader :open
|
9
|
+
attr_accessor :api_key, :host, :default_app, :ip, :mac
|
10
|
+
|
8
11
|
def initialize(api_key, hostname, options = {})
|
9
12
|
@conn = HTTP.persistent LogDNA::INGESTER_DOMAIN
|
10
13
|
opts = fill_opts_with_defaults(options)
|
data/lib/logdna/version.rb
CHANGED
data/logdna.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'http', '~> 2.0'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
26
|
-
spec.add_development_dependency 'rake', '~> 10.
|
27
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
28
|
-
spec.add_development_dependency 'webmock', '~> 2.
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.5'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
|
+
spec.add_development_dependency 'webmock', '~> 2.3'
|
29
29
|
end
|
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: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edwin Lai
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -44,42 +44,42 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '10.
|
47
|
+
version: '10.5'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '10.
|
54
|
+
version: '10.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
61
|
+
version: '3.5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
68
|
+
version: '3.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
75
|
+
version: '2.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '2.
|
82
|
+
version: '2.3'
|
83
83
|
description:
|
84
84
|
email: edwin@logdna.com
|
85
85
|
executables: []
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.8
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: LogDNA extension to ruby logger
|