colortail 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ pkg
2
+ doc
3
+ Manifest
4
+ .swp
@@ -0,0 +1,3 @@
1
+ ### colortail 0.0.0 2010-04-19
2
+
3
+ * Initial release
@@ -0,0 +1,3 @@
1
+ ### colortail 0.0.0 2010-04-19
2
+
3
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Eric Lubow
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # ColorTail #
2
+
3
+ What does ColorTail do for me?
4
+
5
+ ColorTail provides a cool way for you to configure how logfiles (or any other files for that matter) look when you tail them.
6
+
7
+ ## Installation ##
8
+
9
+ ### Install the gem ##
10
+ gem install colortail
11
+
12
+ ## Using ColorTail ##
13
+
14
+ By default, ColorTail does absolutely nothing other than just tail a file normally (similar to the trust old unix tool 'tail -f'). But what good what writing a gem be if it just mimiced existing functionality.
15
+
16
+ ## Conifguring ColorTail ##
17
+
18
+ Configuring ColorTail is easy. In your home directory, create a file .colortailrc. This file will contain a group of ruby arrays similar to the ones laid out in the example config **examples/colortail.rb**. These arrays are called groups. Any group can be loaded via the command line using the **-g** switch (more on this below).
19
+
20
+ The standard configuration file is **.colortailrc**. It needs to be in the format of a Ruby hash.
21
+
22
+ ## Usage ##
23
+
24
+ Using ColorTail is similar to using tail. The main assumption is that you will always be _indefinitely_ tail'ing a file. Currently ColorTail only allows for tailing 1 file.
25
+
26
+ #### Tailing with groups
27
+
28
+ The command below will tail the **/var/log/messages** file using the syslog group. The example config **examples/colortail.rb** shows a _syslog_ grouping that is used in command below:
29
+
30
+ # colortail -g syslog /var/log/messages
31
+
32
+ ## Author ##
33
+
34
+ Eric Lubow <eric at lubow dot org>
35
+
36
+ * Web: [http://eric.lubow.org/](http://eric.lubow.org)
37
+ * Twitter: [elubow](http://twitter.com/elubow)
38
+
39
+ ## Note on Patches/Pull Requests
40
+
41
+ * Fork the project.
42
+ * Make your feature addition or bug fix.
43
+ * Add tests for it. This is important so I don't break it in a
44
+ future version unintentionally.
45
+ * Commit, do not mess with rakefile, version, or history.
46
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
47
+ * Send me a pull request. Bonus points for topic branches.
48
+
49
+ ## Copyright
50
+
51
+ Copyright (c) 2010 Eric Lubow. See LICENSE for details.
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "colortail"
8
+ gem.executables = "colortail"
9
+ gem.summary = "Tail a file and color lines based on regular expressions within that line"
10
+ gem.description = "Tail a file and color lines based on regular expressions within that line"
11
+ gem.email = "eric@lubow.org"
12
+ gem.homepage = "http://codaset.com/elubow/colortail"
13
+ gem.authors = ["Eric Lubow"]
14
+ gem.add_dependency 'file-tail'
15
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ task :test => :check_dependencies
30
+
31
+ task :default => :test
32
+
33
+ require 'rake/rdoctask'
34
+ Rake::RDocTask.new do |rdoc|
35
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
36
+
37
+ rdoc.rdoc_dir = 'rdoc'
38
+ rdoc.title = "colortail #{version}"
39
+ rdoc.rdoc_files.include('README*')
40
+ rdoc.rdoc_files.include('lib/**/*.rb')
41
+ end
@@ -0,0 +1,9 @@
1
+ * General
2
+ * Added multithreading to allow for tailing multiple files simultaneously
3
+
4
+ * Add Testing
5
+
6
+ * Add option to tail file (-f) or work like tail with (-XX) which is a line count
7
+
8
+ * Errors
9
+ * Handle when there is no 'group' in config file
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'colortail'
4
+
5
+ exit ColorTail::Application.run!(*ARGV)
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{colortail}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Eric Lubow"]
12
+ s.date = %q{2010-04-19}
13
+ s.default_executable = %q{colortail}
14
+ s.description = %q{Tail a file and color lines based on regular expressions within that line}
15
+ s.email = %q{eric@lubow.org}
16
+ s.executables = ["colortail"]
17
+ s.extra_rdoc_files = [
18
+ "ChangeLog.markdown",
19
+ "LICENSE",
20
+ "README.markdown"
21
+ ]
22
+ s.files = [
23
+ ".gitignore",
24
+ "Changelog.markdown",
25
+ "LICENSE",
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "TODO.markdown",
29
+ "VERSION",
30
+ "bin/colortail",
31
+ "colortail.gemspec",
32
+ "examples/colortail.rb",
33
+ "examples/test.log",
34
+ "lib/colortail.rb",
35
+ "lib/colortail/application.rb",
36
+ "lib/colortail/configuration.rb",
37
+ "test/helper.rb",
38
+ "test/test_colortail.rb"
39
+ ]
40
+ s.homepage = %q{http://codaset.com/elubow/colortail}
41
+ s.rdoc_options = ["--charset=UTF-8"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = %q{1.3.5}
44
+ s.summary = %q{Tail a file and color lines based on regular expressions within that line}
45
+ s.test_files = [
46
+ "test/helper.rb",
47
+ "test/test_colortail.rb",
48
+ "examples/colortail.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_runtime_dependency(%q<file-tail>, [">= 0"])
57
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<file-tail>, [">= 0"])
60
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<file-tail>, [">= 0"])
64
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'colortail'
3
+
4
+ Groupings = {
5
+
6
+ # This default matching scheme
7
+ 'default' => [],
8
+
9
+ # Matchers for syslog
10
+ 'syslog' => [
11
+ { :match => /EMERGENCY/, :color => :red, :attribute => :reverse },
12
+ { :match => /FATAL/, :color => :red, :attribute => :bright },
13
+ { :match => /CRITICAL/, :color => :red },
14
+ { :match => /DEBUG/, :color => :green },
15
+ { :match => /ERROR/, :color => :green },
16
+ { :match => /INFO/, :color => :none },
17
+ { :match => /WARN/, :color => :yellow }
18
+ ]
19
+
20
+ }
@@ -0,0 +1,6 @@
1
+ 2010-04-14 12:51:21,088 NONE Starting new creation process
2
+ 2010-04-15 02:18:12,693 ERROR Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'yes''' at line 1
3
+ 2010-04-15 12:51:21,088 DEBUG Debugging enabled
4
+ 2010-04-15 12:51:21,123 INFO Creating new File
5
+ 2010-04-15 12:51:21,242 CRITICAL Cannot proceed without -F/--force option
6
+ 2010-04-15 12:52:27,852 EMERGENCY Shutting down immediately
@@ -0,0 +1,77 @@
1
+ require 'rubygems'
2
+ require 'file/tail'
3
+
4
+ dir = File.dirname(__FILE__) + '/colortail'
5
+
6
+ require dir + '/application'
7
+ require dir + '/configuration'
8
+
9
+ module ColorTail
10
+ class Colorize
11
+ COLORS = {
12
+ :none => "0",
13
+ :black => "30",
14
+ :red => "31",
15
+ :green => "32",
16
+ :yellow => "33",
17
+ :blue => "34",
18
+ :magenta => "35",
19
+ :cyan => "36",
20
+ :white => "37"
21
+ }
22
+
23
+ ATTRIBUTES = {
24
+ :bright => 1,
25
+ :dim => 2,
26
+ :underscore => 4,
27
+ :blink => 5,
28
+ :reverse => 7,
29
+ :hidden => 8
30
+ }
31
+
32
+ @@color_matchers = []
33
+
34
+ def log(filename, message, line_prefix=nil)
35
+ # Add the filename to the message
36
+ message = "#{message}"
37
+
38
+ color = :none
39
+ attribute = nil
40
+
41
+ @@color_matchers.each do |filter|
42
+ if message =~ filter[:match]
43
+ color = filter[:color]
44
+ attribute = filter[:attribute]
45
+ message = filter[:prepend] + message unless filter[:prepend].nil?
46
+ break
47
+ end
48
+ end
49
+
50
+ if color != :hide
51
+ current_color = COLORS[color]
52
+ current_attribute = ATTRIBUTES[attribute]
53
+
54
+ line_prefix = colorit(line_prefix.to_s, current_color, current_attribute, nil) unless line_prefix.nil?
55
+ show(colorit(message, current_color, current_attribute), line_prefix)
56
+ end
57
+ end
58
+
59
+ def show(message,prefix)
60
+ puts "#{prefix}#{message}"
61
+ end
62
+
63
+ def colorit(message, color, attribute, nl = "\n")
64
+ attribute = "#{attribute};" if attribute
65
+ "\e[#{attribute}#{color}m" + message.strip + "\e[0m#{nl}"
66
+ end
67
+
68
+ def add_color_matcher( options )
69
+ @@color_matchers.push( options )
70
+ end
71
+ end
72
+
73
+
74
+ class TailFile < File
75
+ include File::Tail
76
+ end
77
+ end
@@ -0,0 +1,57 @@
1
+ module ColorTail
2
+
3
+ class Application
4
+ class << self
5
+ def run!(*arguments)
6
+ opt = ColorTail::Options.new(arguments)
7
+ files = opt[:files]
8
+ options = opt[:options]
9
+
10
+ # Deal with any/all options issues
11
+ if options[:invalid_argument]
12
+ $stderr.puts options[:invalid_argument]
13
+ options[:help] = true
14
+ end
15
+
16
+ if options[:help]
17
+ $stderr.puts options.opts
18
+ return 1
19
+ end
20
+
21
+ begin
22
+ # Read the config file if it exists
23
+ if File.exists?(options[:conf])
24
+ config = ColorTail::Configuration.new(options[:conf])
25
+ @match_group = config.load_opts(options[:group])
26
+ else
27
+ # Create this to ensure we always have a value for this array
28
+ @match_group = Array.new
29
+ end
30
+
31
+ logger = ColorTail::Colorize.new()
32
+
33
+ # Add the color match array if we aren't using the default
34
+ if @match_group.class == Array
35
+ @match_group.each do |matcher|
36
+ logger.add_color_matcher( matcher )
37
+ end
38
+ else
39
+ logger.add_color_matcher( @match_group )
40
+ end
41
+
42
+
43
+ # XXX TODO Just tail the first file
44
+ tailer = ColorTail::TailFile.new( files[0] )
45
+ tailer.interval = 10
46
+ tailer.backward( 10 )
47
+ tailer.tail { |line| logger.log( files[0], line ) }
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+ class FileDoesNotExist < StandardError
55
+ end
56
+
57
+ end
@@ -0,0 +1,87 @@
1
+ module ColorTail
2
+
3
+ class Configuration
4
+ def initialize(conf)
5
+ @config_file = conf
6
+ if File.exists?(conf)
7
+ @config = File.read(conf)
8
+ else
9
+ raise FileDoesNotExist, "Config file #{file} cannot be found."
10
+ end
11
+ end
12
+
13
+ def colorit(group, groupings)
14
+ if groupings.class == Hash
15
+ if groupings.has_key?( group )
16
+ return groupings[group]
17
+ else
18
+ raise ComplexRecord, "No such group '#{group}' in config file"
19
+ end
20
+ else
21
+ raise ComplexRecord, "Config file syntax error"
22
+ end
23
+ end
24
+
25
+ # Load everything from the config file here since the colorit() method
26
+ # isn't available in the configuration object until after a new object
27
+ # has been instantiated.
28
+ def load_opts(group)
29
+ require @config_file
30
+ colorset = self.colorit( group, Groupings )
31
+ return colorset
32
+ end
33
+ end
34
+
35
+ class ComplexRecord < StandardError
36
+ end
37
+
38
+ class Options < Hash
39
+ attr_reader :opts, :orig_args
40
+
41
+ def initialize(args)
42
+ super()
43
+
44
+ user_home = ENV['HOME']
45
+
46
+ @orig_args = args.clone
47
+
48
+ options = {}
49
+
50
+ require 'optparse'
51
+ @opts = OptionParser.new do |o|
52
+ o.banner = "Usage: #{File.basename($0)} <file>"
53
+
54
+ options[:group] = 'default'
55
+ o.on( '-g', '--group <group>', 'Specify the color grouping to use for these files' ) do |group|
56
+ options[:group] = group
57
+ end
58
+
59
+ o.separator ""
60
+
61
+ options[:conf] = "#{user_home}/.colortailrc"
62
+ o.on( '-c', '--conf <FILE>', 'Specify an alternate config file' ) do |file|
63
+ if File.exists?(file)
64
+ options[:conf] = file
65
+ else
66
+ raise FileDoesNotExist, "Config file #{file} cannot be found."
67
+ end
68
+ end
69
+
70
+ options[:help] = false
71
+ o.on( '-h', '--help', 'Display this help screen' ) do
72
+ options[:help] = true
73
+ exit
74
+ end
75
+ end
76
+
77
+ begin
78
+ @opts.parse!(args)
79
+ self[:files] = args
80
+ self[:options] = options
81
+ rescue OptionParser::InvalidOption => e
82
+ self[:invalid_argument] = e.message
83
+ end
84
+ end
85
+ end
86
+
87
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'colortail'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestColortail < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colortail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Lubow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-04-19 00:00:00 -04:00
13
+ default_executable: colortail
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: file-tail
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: thoughtbot-shoulda
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Tail a file and color lines based on regular expressions within that line
36
+ email: eric@lubow.org
37
+ executables:
38
+ - colortail
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - ChangeLog.markdown
43
+ - LICENSE
44
+ - README.markdown
45
+ files:
46
+ - .gitignore
47
+ - Changelog.markdown
48
+ - LICENSE
49
+ - README.markdown
50
+ - Rakefile
51
+ - TODO.markdown
52
+ - VERSION
53
+ - bin/colortail
54
+ - colortail.gemspec
55
+ - examples/colortail.rb
56
+ - examples/test.log
57
+ - lib/colortail.rb
58
+ - lib/colortail/application.rb
59
+ - lib/colortail/configuration.rb
60
+ - test/helper.rb
61
+ - test/test_colortail.rb
62
+ - ChangeLog.markdown
63
+ has_rdoc: true
64
+ homepage: http://codaset.com/elubow/colortail
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.5
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Tail a file and color lines based on regular expressions within that line
91
+ test_files:
92
+ - test/helper.rb
93
+ - test/test_colortail.rb
94
+ - examples/colortail.rb