artifact_logger 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +51 -0
- data/lib/artifact_logger/active_record.rb +19 -0
- data/lib/artifact_logger/engine.rb +6 -0
- data/lib/artifact_logger/model_extensions.rb +34 -0
- data/lib/artifact_logger.rb +24 -0
- data/lib/tasks/artifact_logger_tasks.rake +4 -0
- metadata +55 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= ArtifactLogger
|
2
|
+
|
3
|
+
This is an engine which is designed to be a drop-in logging agent for use in a Rails application.
|
4
|
+
|
5
|
+
Usage:
|
6
|
+
|
7
|
+
# app/models/artifact.rb
|
8
|
+
|
9
|
+
class Artifact < ActiveRecord::Base
|
10
|
+
has_many 'Log::Messages', :as => :artifacts
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
art = Artifact.new
|
15
|
+
|
16
|
+
art.log("Error", "This is an error message")
|
17
|
+
|
18
|
+
art.logs
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'rdoc/task'
|
11
|
+
rescue LoadError
|
12
|
+
require 'rdoc/rdoc'
|
13
|
+
require 'rake/rdoctask'
|
14
|
+
RDoc::Task = Rake::RDocTask
|
15
|
+
end
|
16
|
+
|
17
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'ArtifactLogger'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README.rdoc')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
26
|
+
load 'rails/tasks/engine.rake'
|
27
|
+
|
28
|
+
# Use rspec instead
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
|
32
|
+
RSpec::Core::RakeTask.new(:spec)
|
33
|
+
|
34
|
+
task :default => :spec
|
35
|
+
|
36
|
+
begin
|
37
|
+
require "jeweler"
|
38
|
+
Jeweler::Tasks.new do |gem|
|
39
|
+
gem.name = "active_logger"
|
40
|
+
gem.summary = "Dropin Logging for Rails"
|
41
|
+
gem.description = "A dropin logging engine for rails. It will keep rack of log message against a given record/artifact."
|
42
|
+
gem.files = Dir["{app,lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"]
|
43
|
+
# other fields that would normally go in your gemspec
|
44
|
+
# like authors, email and has_rdoc can also be included here
|
45
|
+
|
46
|
+
end
|
47
|
+
rescue
|
48
|
+
puts "Jeweler or one of its dependencies is not installed."
|
49
|
+
end
|
50
|
+
|
51
|
+
Rake.application.invoke_task(:load_app)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# ActiveRecord augmentations
|
2
|
+
module ArtifactLogger::ActiveRecord
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def enable_artifact_logger options
|
7
|
+
#Configure the has_many
|
8
|
+
has_many :log, :as => :artifact, :class_name => '::Log::Message'
|
9
|
+
#Store the old logging method
|
10
|
+
alias_method :_log, :log
|
11
|
+
remove_method :log
|
12
|
+
|
13
|
+
include ArtifactLogger::ModelExtensions
|
14
|
+
|
15
|
+
#Store the levels which are valid
|
16
|
+
@_valid_levels = options[:levels]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#Model extensions for Artifct Logger
|
2
|
+
module ArtifactLogger::ModelExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def log *params
|
7
|
+
if params.length == 0
|
8
|
+
ArtifactLogger.extend_object(Log::Message.where(:artifact_type => model_name, :artifact_id => nil), self)
|
9
|
+
elsif params.length == 2
|
10
|
+
Log::Message.create :level => params[0], :text => params[1], :artifact_type => model_name
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid_log_levels
|
17
|
+
return @_valid_levels || [:error, :info, :warning]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module InstanceMethods
|
22
|
+
def log *params
|
23
|
+
if params.length != 2
|
24
|
+
ArtifactLogger.extend_object(_log(*params), self)
|
25
|
+
else
|
26
|
+
Log::Message.create :level => params[0], :text => params[1], :artifact => self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_log_levels
|
31
|
+
return self.class.valid_log_levels
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'artifact_logger/engine'
|
2
|
+
require 'artifact_logger/model_extensions'
|
3
|
+
require 'artifact_logger/active_record'
|
4
|
+
|
5
|
+
|
6
|
+
module ArtifactLogger
|
7
|
+
|
8
|
+
def self.extend_object obj, artifact
|
9
|
+
artifact.valid_log_levels.each do |level|
|
10
|
+
obj.define_singleton_method level do |message=nil|
|
11
|
+
if message.nil?
|
12
|
+
artifact.log.log_level(level)
|
13
|
+
else
|
14
|
+
artifact.log.create(:text => message, :level => level)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
return obj
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class ActiveRecord::Base
|
23
|
+
include ArtifactLogger::ActiveRecord
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: artifact_logger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ajrkerr
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-07-08 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
description: A very simple dropin engine for logging information on artifacts in a
|
16
|
+
database.
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/artifact_logger/active_record.rb
|
23
|
+
- lib/artifact_logger/model_extensions.rb
|
24
|
+
- lib/artifact_logger/engine.rb
|
25
|
+
- lib/tasks/artifact_logger_tasks.rake
|
26
|
+
- lib/artifact_logger.rb
|
27
|
+
- MIT-LICENSE
|
28
|
+
- Rakefile
|
29
|
+
- README.rdoc
|
30
|
+
has_rdoc: true
|
31
|
+
homepage:
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.6.2
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: A simple dropin engine for logging information on artifacts in a databse.
|
55
|
+
test_files: []
|