logn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logn.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Marten Veldthuis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Logn
2
+
3
+ Why bother with complicated centralized logging servers with elastic searchers
4
+ when you have a powerful machine running idle on your desk, and you only have
5
+ a few million lines of logs anyway?
6
+
7
+ This gem is meant for those who are not web scale. You don't need to set up
8
+ any servers. Just point it at some log files, and we'll give you a nice
9
+ console where you can specify some filters to drill down to the lines
10
+ you want.
11
+
12
+ ## Installation
13
+
14
+ $ gem install logn
15
+
16
+ ## Usage
17
+
18
+ $ logn *.log
19
+
20
+ Right now, your log files need to be formatted like this:
21
+
22
+ I, [2013-04-22T09:47:33.081972 #12790] ERROR -- : sending.application.area:status {"optional":"json hash","with":"extra event data"}
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/logn ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'logn'
4
+
5
+ events = []
6
+
7
+ ARGF.set_encoding 'utf-8'
8
+ puts start = Time.now
9
+ ARGF.each_line do |line|
10
+ events << Logn::Event.new(line)
11
+ end
12
+ puts Time.now - start
13
+
14
+ require 'pry'
15
+ binding.pry
@@ -0,0 +1,3 @@
1
+ module Logn
2
+ VERSION = "0.0.1"
3
+ end
data/lib/logn.rb ADDED
@@ -0,0 +1,68 @@
1
+ # coding: utf-8
2
+ require "logn/version"
3
+ require 'ostruct'
4
+ require 'time'
5
+ require 'json'
6
+ require 'yajl'
7
+
8
+ module Logn
9
+ class Event
10
+ LOG_LINE_REGEX = /^
11
+ (?<level>\w)
12
+ ,\s
13
+ \[
14
+ (?<timestamp>\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d.\d+)
15
+ \s
16
+ \#(?<pid>\d+)
17
+ \]
18
+ \s+
19
+ (?<severity>\w+)
20
+ \s--\s:\s
21
+ (?<sender>[\w.]+)
22
+ (?<event>:\w+)?
23
+ \s
24
+ (?<json>.*)
25
+ $/x
26
+
27
+ def initialize(line)
28
+ @line = line
29
+ end
30
+
31
+ def level
32
+ match[:level]
33
+ end
34
+
35
+ def timestamp
36
+ @timestamp ||= Time.iso8601(match[:timestamp])
37
+ end
38
+
39
+ def pid
40
+ match[:pid]
41
+ end
42
+
43
+ def severity
44
+ @severity ||= match[:severity].downcase.to_sym
45
+ end
46
+
47
+ def sender
48
+ match[:sender]
49
+ end
50
+
51
+ def event
52
+ @event ||= (match[:event] and match[:event].gsub(/^:/, ''))
53
+ end
54
+
55
+ def metadata
56
+ return nil unless match[:json]
57
+ @metadata ||= JSON.parse(match[:json])
58
+ end
59
+
60
+ private
61
+
62
+ def match
63
+ @match ||= @line.match(LOG_LINE_REGEX)
64
+ raise "Could not parse #{line}" unless @match
65
+ @match
66
+ end
67
+ end
68
+ end
data/logn.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logn/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logn"
8
+ spec.version = Logn::VERSION
9
+ spec.authors = ["Marten Veldthuis"]
10
+ spec.email = ["marten@veldthuis.com"]
11
+ spec.description = %q{Logn parses and filters log files}
12
+ spec.summary = %q{With Logn you can easily grep through formatted logfiles to search and correlate entries.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'pry'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
data/spec/logn_spec.rb ADDED
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ require 'logn'
3
+
4
+ describe 'parsing a log event' do
5
+ let(:line) { %(I, [2013-05-21T16:14:51.587433 #2313] INFO -- : roqua.web:started {"uuid":"123","method":"GET","path":"/epd/patient/new_outcomes/6/scores","format":"html","controller":"epd/new_outcomes","action":"scores","status":200,"params":{"id":"6"},"session_id":"0012","session":{"logged_in_at":"2013-05-21T16:14:37+02:00","user_id":37},"duration":56.24,"view":40.91,"db":2.33}) }
6
+ let(:event) { Logn::Event.new(line) }
7
+
8
+ it 'parses the level' do
9
+ event.level.should == 'I'
10
+ end
11
+
12
+ it 'parses the timestamp' do
13
+ event.timestamp.should == Time.local(2013, 05, 21, 16, 14, 51, 587433)
14
+ end
15
+
16
+ it 'parses the pid' do
17
+ event.pid.should == '2313'
18
+ end
19
+
20
+ it 'parses the severity' do
21
+ event.severity.should == :info
22
+ end
23
+
24
+ it 'parses the sender' do
25
+ event.sender.should == 'roqua.web'
26
+ end
27
+
28
+ it 'parses the event' do
29
+ event.event.should == 'started'
30
+ end
31
+
32
+ it 'parses the json hash' do
33
+ event.metadata.should == {
34
+ "uuid"=> "123",
35
+ "method"=>"GET",
36
+ "path"=> "/epd/patient/new_outcomes/6/scores",
37
+ "format"=>"html",
38
+ "controller"=>"epd/new_outcomes",
39
+ "action"=>"scores",
40
+ "status"=>200,
41
+ "params"=>{"id"=>"6"},
42
+ "session_id"=>"0012",
43
+ "session"=>{"logged_in_at"=>"2013-05-21T16:14:37+02:00","user_id"=>37},
44
+ "duration"=>56.24,
45
+ "view"=>40.91,
46
+ "db"=>2.33
47
+ }
48
+ end
49
+
50
+ it 'parses errors' do
51
+ line = %(E, [2013-04-22T09:47:33.081972 #12790] ERROR -- : roqua.hl7.a19:failed {"exception":{},"message":"Connection timed out - connect(2)"})
52
+ event = Logn::Event.new(line)
53
+ event.level.should == 'E'
54
+ event.severity.should == :error
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marten Veldthuis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pry
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Logn parses and filters log files
63
+ email:
64
+ - marten@veldthuis.com
65
+ executables:
66
+ - logn
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/logn
77
+ - lib/logn.rb
78
+ - lib/logn/version.rb
79
+ - logn.gemspec
80
+ - spec/logn_spec.rb
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: -487170330778638442
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: -487170330778638442
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.25
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: With Logn you can easily grep through formatted logfiles to search and correlate
112
+ entries.
113
+ test_files:
114
+ - spec/logn_spec.rb