log_master 0.1.4 → 0.2.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.
data/README.rdoc CHANGED
@@ -1,6 +1,45 @@
1
- = log_master
1
+ == log_master
2
2
 
3
- Description goes here.
3
+ A simple library for mailing log (or whatever) files back to you!
4
+
5
+ This was written as a failsafe for cron tasks who's output we wanted conditionally sent to
6
+ one email address or another. The idea is that under normal conditions you don't want to spam
7
+ your inbox with emails stating 'everything is fine.' Instead you can have it go directly into
8
+ archive unless it has some idea that something is going wrong.
9
+
10
+ == Installation
11
+ $ sudo gem install log_master
12
+
13
+ == Instructions
14
+ $ log_master -p [--log-pattern] PATTERN [-c | --config PATH]
15
+
16
+ Where PATTERN is a glob representing the files you would like to email and PATH is the path to
17
+ a configuration file (defaults to config/log_master.rb)
18
+
19
+ == Configuration
20
+
21
+ You should put something like the following in config/log_master.rb
22
+
23
+ LogMaster::Configuration.configure do |config|
24
+ config.title = "Cron Update Notice"
25
+ config.reporting = {:warn => /error/i, :error => /aborted/i}
26
+ config.failure_conditions = [:error]
27
+
28
+ config.recipients = {:success => 'success@example.com', :failure => 'failure@example.com' }
29
+
30
+ config.reply_to = "no-reply@likeassets.com"
31
+ config.from = "mail@likeassets.com"
32
+ end
33
+
34
+ I only provided direct ActionMailer setters for from and reply_to as the intention is to let LogMaster
35
+ determine via failure_conditions and its recipients attribute where the email should go. Feel free to fork
36
+ and change this if it leaves something to be desired.
37
+
38
+ == Customization
39
+
40
+ The 'reporting' attribute can take a completely custom hash of 'name' => 'regexp' so you can define your
41
+ own warning, failure, info or debug conditions. Only if it contains anything specified in 'failure_conditions'
42
+ will it consider it a failure.
4
43
 
5
44
  == Note on Patches/Pull Requests
6
45
 
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ begin
15
15
  gem.email = "zbelzer@gmail.com"
16
16
  gem.homepage = "http://github.com/moneypools/log_master"
17
17
  gem.authors = ["Zachary Belzer"]
18
- gem.add_dependency "actionmailer"
18
+ gem.add_dependency "actionmailer", ">= 2.2.2"
19
19
  gem.add_development_dependency "rspec"
20
20
  gem.add_development_dependency "email_spec", " >= 0.3.5"
21
21
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
data/bin/log_master ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'optparse'
5
+ require 'log_master'
6
+
7
+ options = Hash.new
8
+ log_pattern = nil
9
+
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: log_master [options]"
12
+
13
+ opts.on('-p', '--log-pattern PATTERN', "A globbing pattern designating files to email") do |pattern|
14
+ log_pattern = pattern
15
+ end
16
+
17
+ opts.on('-c', '--config [FILE]', 'A configuration file. Default: config/log_master.rb') do |file|
18
+ options[:file] = file if file
19
+ end
20
+ end.parse!
21
+
22
+ if log_pattern.nil? || log_pattern == ""
23
+ $stderr.puts "You must supply a log-pattern. See --help"
24
+ exit(1)
25
+ end
26
+
27
+ if files = Dir[log_pattern] and files.empty?
28
+ $stderr.puts "No files were found matching pattern '#{log_pattern}'"
29
+ exit(1)
30
+ else
31
+ LogMaster::Director.execute(files, options)
32
+ end
@@ -5,11 +5,17 @@ module LogMaster
5
5
 
6
6
  attr_accessor :reports, :logs
7
7
 
8
- def initialize(files)
9
- raise "LogMaster has not yet been configured" unless Configuration.configured?
10
- @configuration = Configuration.instance
8
+ def self.execute(files, options={})
9
+ new(files, options).run
10
+ end
11
+
12
+ def initialize(files, options={})
13
+ @options = options
14
+ @options[:file] ||= 'config/log_master.rb'
15
+
11
16
  @reports = {}
12
17
 
18
+ load_configuration
13
19
  create_log_files(files)
14
20
  end
15
21
 
@@ -17,6 +23,19 @@ module LogMaster
17
23
  aggregate!
18
24
  send_email
19
25
  end
26
+
27
+ def load_configuration
28
+ require @options[:file] if File.exists?(@options[:file])
29
+
30
+ # config = File.read(@options[:file])
31
+ # eval(config)
32
+
33
+ if Configuration.configured?
34
+ @configuration = Configuration.instance
35
+ else
36
+ raise "[fail] LogMaster is not configured"
37
+ end
38
+ end
20
39
 
21
40
  def aggregate!
22
41
  logs.each do |l|
data/log_master.gemspec CHANGED
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{log_master}
8
- s.version = "0.1.4"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Zachary Belzer"]
12
- s.date = %q{2009-12-03}
12
+ s.date = %q{2010-01-15}
13
+ s.default_executable = %q{log_master}
13
14
  s.description = %q{Creates and emails a simple report for a set of log (or text) files. Useful for aggretating small log files.}
14
15
  s.email = %q{zbelzer@gmail.com}
16
+ s.executables = ["log_master"]
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE",
17
19
  "README.rdoc"
@@ -23,6 +25,7 @@ Gem::Specification.new do |s|
23
25
  "README.rdoc",
24
26
  "Rakefile",
25
27
  "VERSION",
28
+ "bin/log_master",
26
29
  "features/log_master.feature",
27
30
  "features/step_definitions/email_steps.rb",
28
31
  "features/step_definitions/log_master_steps.rb",
@@ -33,7 +36,6 @@ Gem::Specification.new do |s|
33
36
  "lib/log_master/director.rb",
34
37
  "lib/log_master/log_file.rb",
35
38
  "lib/log_master/notifier.rb",
36
- "lib/log_master/rake/log_task.rb",
37
39
  "lib/templates/log_master/notifier/update_notification.html.erb",
38
40
  "log_master.gemspec",
39
41
  "spec/configuration_spec.rb",
@@ -43,8 +45,7 @@ Gem::Specification.new do |s|
43
45
  "spec/fixtures/log_without_errors.log",
44
46
  "spec/log_file_spec.rb",
45
47
  "spec/notification_spec.rb",
46
- "spec/spec_helper.rb",
47
- "tasks/log_master.rake"
48
+ "spec/spec_helper.rb"
48
49
  ]
49
50
  s.homepage = %q{http://github.com/moneypools/log_master}
50
51
  s.rdoc_options = ["--charset=UTF-8"]
@@ -64,16 +65,16 @@ Gem::Specification.new do |s|
64
65
  s.specification_version = 3
65
66
 
66
67
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
- s.add_runtime_dependency(%q<actionmailer>, [">= 0"])
68
+ s.add_runtime_dependency(%q<actionmailer>, [">= 2.2.2"])
68
69
  s.add_development_dependency(%q<rspec>, [">= 0"])
69
70
  s.add_development_dependency(%q<email_spec>, [">= 0.3.5"])
70
71
  else
71
- s.add_dependency(%q<actionmailer>, [">= 0"])
72
+ s.add_dependency(%q<actionmailer>, [">= 2.2.2"])
72
73
  s.add_dependency(%q<rspec>, [">= 0"])
73
74
  s.add_dependency(%q<email_spec>, [">= 0.3.5"])
74
75
  end
75
76
  else
76
- s.add_dependency(%q<actionmailer>, [">= 0"])
77
+ s.add_dependency(%q<actionmailer>, [">= 2.2.2"])
77
78
  s.add_dependency(%q<rspec>, [">= 0"])
78
79
  s.add_dependency(%q<email_spec>, [">= 0.3.5"])
79
80
  end
@@ -3,6 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  module LogMaster
4
4
  describe "Director" do
5
5
  before do
6
+ Configuration.stub!(:configured?).and_return(true)
6
7
  @files = %w(log_without_errors.log log_with_errors.log).map {|f| log_file_path(f) }
7
8
  end
8
9
 
@@ -11,9 +12,8 @@ module LogMaster
11
12
  end
12
13
 
13
14
  it "should raise error if not configured" do
14
- Configuration.instance.reset_configured_status!
15
+ Configuration.stub!(:configured?).and_return(false)
15
16
  lambda {Director.new(@files)}.should raise_error
16
- Configuration.configure {|c|} # Reset configured state
17
17
  end
18
18
 
19
19
  describe "aggregate" do
@@ -24,7 +24,6 @@ module LogMaster
24
24
  end
25
25
  end
26
26
 
27
-
28
27
  describe "successful?" do
29
28
  it "should be true when no aggregate count for failure_conditions" do
30
29
  log_master = Director.new(log_file_path('log_without_errors.log'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Belzer
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-03 00:00:00 -06:00
13
- default_executable:
12
+ date: 2010-01-15 00:00:00 -06:00
13
+ default_executable: log_master
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionmailer
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0"
23
+ version: 2.2.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
@@ -44,8 +44,8 @@ dependencies:
44
44
  version:
45
45
  description: Creates and emails a simple report for a set of log (or text) files. Useful for aggretating small log files.
46
46
  email: zbelzer@gmail.com
47
- executables: []
48
-
47
+ executables:
48
+ - log_master
49
49
  extensions: []
50
50
 
51
51
  extra_rdoc_files:
@@ -58,6 +58,7 @@ files:
58
58
  - README.rdoc
59
59
  - Rakefile
60
60
  - VERSION
61
+ - bin/log_master
61
62
  - features/log_master.feature
62
63
  - features/step_definitions/email_steps.rb
63
64
  - features/step_definitions/log_master_steps.rb
@@ -68,7 +69,6 @@ files:
68
69
  - lib/log_master/director.rb
69
70
  - lib/log_master/log_file.rb
70
71
  - lib/log_master/notifier.rb
71
- - lib/log_master/rake/log_task.rb
72
72
  - lib/templates/log_master/notifier/update_notification.html.erb
73
73
  - log_master.gemspec
74
74
  - spec/configuration_spec.rb
@@ -79,7 +79,6 @@ files:
79
79
  - spec/log_file_spec.rb
80
80
  - spec/notification_spec.rb
81
81
  - spec/spec_helper.rb
82
- - tasks/log_master.rake
83
82
  has_rdoc: true
84
83
  homepage: http://github.com/moneypools/log_master
85
84
  licenses: []
@@ -1,20 +0,0 @@
1
- require 'log_master'
2
-
3
- module LogMaster
4
- module Rake
5
- class LogTask < ::Rake::Task
6
- attr_accessor :log_pattern
7
-
8
- protected
9
- def execute(*args)
10
- super
11
- run_log_master
12
- end
13
-
14
- def run_log_master
15
- files = Dir[log_pattern]
16
- LogMaster::Director.new(files).run
17
- end
18
- end
19
- end
20
- end
@@ -1,18 +0,0 @@
1
- namespace :log_master do
2
- task :configure do
3
- require 'actionmailer'
4
- ActionMailer::Base.delivery_method = :sendmail
5
-
6
- LogMaster::Configuration.configure do |config|
7
- config.title = "This is a sample email"
8
- config.recipients = {:success => 'localhost', :failure => 'localhost' }
9
- config.reporting = {:warn => /WARN/, :error => /ERROR/, :fatal => /FATAL/}
10
- config.reply_to = "sender@example.com"
11
- end
12
- end
13
-
14
- desc "Runs log master on specified log file"
15
- LogMaster::Rake::LogTask.define_task "test" => :configure do |t|
16
- t.log_pattern = ENV['log_pattern'] || "spec/fixtures/log_with_errors.log"
17
- end
18
- end