herokulogs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in herokulogs.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Thorben Schröder
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.
@@ -0,0 +1,40 @@
1
+ # Herokulogs
2
+
3
+ A tool to get a clear view on log tails of heroku apps
4
+
5
+ ## Usage
6
+
7
+ ``
8
+ $ heroku logs --tail | herokulogs FORMAT
9
+ ``
10
+
11
+ ### Format options:
12
+
13
+ ``
14
+ 2: http status
15
+ b: bytes
16
+ c: connect time
17
+ d: date
18
+ f: fwd IP
19
+ h: host
20
+ l: log level
21
+ m: method
22
+ p: path
23
+ s: service time
24
+ t: type
25
+ y: dyno
26
+ ``
27
+
28
+ ## Examples
29
+
30
+ ``
31
+ # Log status code, HTTP method and path:
32
+ $ heroku logs --tail | herokulogs.rb 2mp
33
+ ``
34
+
35
+ Optionally you can add a second paramter which is interpreted as a Ruby regex that has to match on the raw log line in order to print it to STDOUT.
36
+
37
+ ``
38
+ # Log path only when it comes from a web dyno
39
+ $ heroku logs --tail | herokulogs p "dyno=web\.\d+"
40
+ ``
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'herokulogs'
4
+
5
+ cli = Herokulogs::CLI.new
6
+ cli.run!
7
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'herokulogs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "herokulogs"
8
+ spec.version = Herokulogs::VERSION
9
+ spec.authors = ["Thorben Schröder"]
10
+ spec.email = ["info@thorbenschroeder.de"]
11
+ spec.description = %q{A tool to get a clear view on log tails of heroku apps}
12
+ spec.summary = %q{A tool to get a clear view on log tails of heroku apps}
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,5 @@
1
+ require 'time'
2
+
3
+ require "herokulogs/version"
4
+ require "herokulogs/formatter"
5
+ require "herokulogs/cli"
@@ -0,0 +1,20 @@
1
+ module Herokulogs
2
+ class CLI
3
+ def initialize
4
+ @formatter = Formatter.new(ARGV.first)
5
+ @guard = Regexp.new(ARGV[1] || "")
6
+
7
+ puts "herokulogs output format: #{@formatter.output_format.join(" ")}"
8
+ puts "herokulogs guard: #{@guard.inspect}" if @guard != //
9
+ end
10
+
11
+ def run!
12
+ STDIN.each do |line|
13
+ if line.match(@guard)
14
+ formatted = @formatter.format(line.chomp)
15
+ puts formatted if formatted
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,95 @@
1
+ module Herokulogs
2
+ class Formatter
3
+ FORMAT = Regexp.new([
4
+ /(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+\+\d{2}:\d{2}) /,
5
+ /([^:]+): /,
6
+ /at=(\S+) /,
7
+ /method=(\S+) /,
8
+ /path=(\S+) /,
9
+ /host=(\S+) /,
10
+ /fwd="([^"]+)" /,
11
+ /dyno=(\S+) /,
12
+ /connect=(\d+)ms /,
13
+ /service=(\d+)ms /,
14
+ /status=(\d+) /,
15
+ /bytes=(\d+)/
16
+ ].join)
17
+
18
+ OUTPUT_FORMAT_OPTIONS = {
19
+ "2" => :status,
20
+ "b" => :bytes,
21
+ "c" => :connect,
22
+ "d" => :date,
23
+ "f" => :fwd,
24
+ "h" => :host,
25
+ "l" => :log_level,
26
+ "m" => :method,
27
+ "p" => :path,
28
+ "s" => :service,
29
+ "t" => :type,
30
+ "y" => :dyno,
31
+ }
32
+
33
+ FORMATTER = {
34
+ :status => "%3d",
35
+ :bytes => "%08d",
36
+ :connect => "%05dms",
37
+ :date => lambda {|e| t = Time.parse(e); t.strftime "%Y-%m-%d %H:%M:%S"},
38
+ :fwd => "%15s",
39
+ :host => "%20s",
40
+ :log_level => "%5s",
41
+ :method => "%7s",
42
+ :path => "%-40s",
43
+ :service => "%05dms",
44
+ :type => "%15s",
45
+ :dyno => "%8s"
46
+ }
47
+
48
+ attr_reader :output_format
49
+
50
+ def initialize(format_string)
51
+ output_format = format_string
52
+ if output_format.empty?
53
+ STDERR.puts "herokulogs format missing"
54
+ exit(false)
55
+ end
56
+ @output_format = output_format.chars.map {|c| OUTPUT_FORMAT_OPTIONS[c]}.compact
57
+ end
58
+
59
+ def format(line)
60
+ input = construct_input_hash(line)
61
+ return unless input
62
+
63
+ @output_format.map do |element|
64
+ formatter = FORMATTER[element]
65
+ if formatter.respond_to?(:call)
66
+ formatter.call(input[element])
67
+ else
68
+ formatter % input[element]
69
+ end
70
+ end.join(" ")
71
+ end
72
+
73
+ protected
74
+ def construct_input_hash(line)
75
+ match = line.match(FORMAT)
76
+ return unless match
77
+
78
+ date, type, log_level, method, path, host, fwd, dyno, connect, service, status, bytes = match.captures
79
+ {
80
+ :date => date,
81
+ :type => type,
82
+ :log_level => log_level,
83
+ :method => method,
84
+ :path => path,
85
+ :host => host,
86
+ :fwd => fwd,
87
+ :dyno => dyno,
88
+ :connect => connect,
89
+ :service => service,
90
+ :status => status,
91
+ :bytes => bytes
92
+ }
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,3 @@
1
+ module Herokulogs
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: herokulogs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thorben Schröder
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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: '0'
46
+ description: A tool to get a clear view on log tails of heroku apps
47
+ email:
48
+ - info@thorbenschroeder.de
49
+ executables:
50
+ - herokulogs
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/herokulogs
60
+ - herokulogs.gemspec
61
+ - lib/herokulogs.rb
62
+ - lib/herokulogs/cli.rb
63
+ - lib/herokulogs/formatter.rb
64
+ - lib/herokulogs/version.rb
65
+ homepage: ''
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.25
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A tool to get a clear view on log tails of heroku apps
90
+ test_files: []