artifact_logger 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/artifact_logger.rb +8 -1
- data/lib/artifact_logger/model_extensions.rb +14 -4
- metadata +2 -2
data/lib/artifact_logger.rb
CHANGED
@@ -5,7 +5,8 @@ require 'artifact_logger/active_record'
|
|
5
5
|
|
6
6
|
module ArtifactLogger
|
7
7
|
|
8
|
-
|
8
|
+
#Extends a log object to add additional functionality
|
9
|
+
def self.extend_log_object obj, artifact
|
9
10
|
artifact.valid_log_levels.each do |level|
|
10
11
|
obj.define_singleton_method level do |message=nil|
|
11
12
|
if message.nil?
|
@@ -14,6 +15,12 @@ module ArtifactLogger
|
|
14
15
|
artifact.log.create(:text => message, :level => level)
|
15
16
|
end
|
16
17
|
end
|
18
|
+
|
19
|
+
# Adds a method such as:
|
20
|
+
# artifact.log.error? which returns true if there
|
21
|
+
obj.define_singleton_method "#{level}?" do
|
22
|
+
!artifact.log.log_level(level).empty?
|
23
|
+
end
|
17
24
|
end
|
18
25
|
return obj
|
19
26
|
end
|
@@ -3,9 +3,16 @@ module ArtifactLogger::ModelExtensions
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
+
#Provides two different functionalities:
|
7
|
+
# Artifact.log # => log message object
|
8
|
+
# Artifact.log :level, "Message" # Creates a new message
|
6
9
|
def log *params
|
7
10
|
if params.length == 0
|
8
|
-
|
11
|
+
#Return a set of messages, however extend the class at runtime
|
12
|
+
#This allows you to use:
|
13
|
+
#Artifact.log.error
|
14
|
+
#Artifact.log.error?
|
15
|
+
ArtifactLogger.extend_log_object(Log::Message.where(:artifact_type => model_name, :artifact_id => nil), self)
|
9
16
|
elsif params.length == 2
|
10
17
|
Log::Message.create :level => params[0], :text => params[1], :artifact_type => model_name
|
11
18
|
else
|
@@ -19,11 +26,14 @@ module ArtifactLogger::ModelExtensions
|
|
19
26
|
end
|
20
27
|
|
21
28
|
module InstanceMethods
|
29
|
+
#Provides two different functionalities:
|
30
|
+
# artifact.log # => log message object
|
31
|
+
# artifact.log :level, "Message" # Creates a new message
|
22
32
|
def log *params
|
23
|
-
if params.length
|
24
|
-
ArtifactLogger.extend_object(_log(*params), self)
|
25
|
-
else
|
33
|
+
if params.length == 2
|
26
34
|
Log::Message.create :level => params[0], :text => params[1], :artifact => self
|
35
|
+
else
|
36
|
+
ArtifactLogger.extend_log_object(_log(*params), self)
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artifact_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-17 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
description: A very simple dropin engine for logging information on artifacts in a
|