log_me 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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Robert Neumayr
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,50 @@
1
+ = LogMe
2
+
3
+ Adds custom logging functionality to controllers and models in a Rails application.
4
+
5
+ == Installation
6
+
7
+ Add the gem to your gemfile
8
+
9
+ gem 'log_me'
10
+
11
+ == Example usage
12
+
13
+ class Post < ActiveRecord::Base
14
+ log_me # turn on the logging functionality for this class
15
+
16
+ def an_instance_method
17
+ # ... do something ...
18
+ log "This is a logging message with severity info"
19
+ log "This is a logging message with severity error", :error
20
+ end
21
+
22
+ def self.a_class_method
23
+ # since logging is done on class level
24
+ # this isn't a problem
25
+ log "This is a logging message in a class method, as warning", :warning
26
+ end
27
+ end
28
+
29
+ The standard behaviour cares about the naming of the logfile. In the example above the logfile can be found under YourApplication/log/post.log
30
+
31
+ To alter this behaviour just provide an own name, like so:
32
+
33
+ class Post < ActiveRecord::Base
34
+ log_me "my_own_logfile_name"
35
+
36
+ # ...
37
+ end
38
+
39
+ In this style the logfile can be found under YourApplication/log/my_own_logfile_name.log
40
+
41
+ == Additions
42
+
43
+ The logging functionality is added to `ActiveRecord::Base` and `ActionController::Base`. So each class that inherits from either of them is able
44
+ to use the logging functionality.
45
+
46
+
47
+ == Authors and credits
48
+
49
+ Author:: Robert Neumayr
50
+ Original idea:: http://www.tonyamoyal.com/2009/09/24/specific-logging-for-your-rails-models-the-easy-way/
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "log_me"
@@ -0,0 +1,2 @@
1
+ require 'log_me/controller_additions'
2
+ require 'log_me/model_additions'
@@ -0,0 +1,30 @@
1
+ module LogMe
2
+ module ControllerAdditions
3
+ module ClassMethods
4
+ def log_me(name = nil)
5
+ name ||= self.controller_name.underscore
6
+ @@log_me_file = Rails.root.join('log', "#{name}.log").to_s
7
+ end
8
+
9
+ def log(message, severity = :info)
10
+ @@log_me_log ||= Logger.new(@@log_me_file)
11
+ @@log_me_log.send severity, "[#{Time.now.to_s(:db)}] [#{severity.to_s.capitalize}] #{message}"
12
+ end
13
+ end
14
+
15
+ module InstanceMethods
16
+ def log(message, severity = :info)
17
+ self.class.log(message, severity);
18
+ end
19
+ end
20
+
21
+ def self.included(receiver)
22
+ receiver.extend ClassMethods
23
+ receiver.send :include, InstanceMethods
24
+ end
25
+ end
26
+ end
27
+
28
+ ActionController::Base.class_eval do
29
+ include LogMe::ControllerAdditions
30
+ end
@@ -0,0 +1,30 @@
1
+ module LogMe
2
+ module ModelAdditions
3
+ module ClassMethods
4
+ def log_me(name = nil)
5
+ name ||= self.model_name.underscore
6
+ @@log_me_file = Rails.root.join('log', "#{name}.log").to_s
7
+ end
8
+
9
+ def log(message, severity = :info)
10
+ @@log_me_log ||= Logger.new(@@log_me_file)
11
+ @@log_me_log.send severity, "[#{Time.now.to_s(:db)}] [#{severity.to_s.capitalize}] #{message}"
12
+ end
13
+ end
14
+
15
+ module InstanceMethods
16
+ def log(message, severity = :info)
17
+ self.class.log(message, severity);
18
+ end
19
+ end
20
+
21
+ def self.included(receiver)
22
+ receiver.extend ClassMethods
23
+ receiver.send :include, InstanceMethods
24
+ end
25
+ end
26
+ end
27
+
28
+ ActiveRecord::Base.class_eval do
29
+ include LogMe::ModelAdditions
30
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: log_me
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: '1.0'
6
+ platform: ruby
7
+ authors:
8
+ - Robert Neumayr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.9
20
+ none: false
21
+ name: rails
22
+ type: :development
23
+ prerelease: false
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: 3.0.9
29
+ none: false
30
+ description: Adds customized logging functionality to ActionController and ActiveRecord
31
+ in a Rails application.
32
+ email: kontakt@icatcher.at
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/log_me/controller_additions.rb
38
+ - lib/log_me/model_additions.rb
39
+ - lib/log_me.rb
40
+ - LICENSE
41
+ - README.rdoc
42
+ - init.rb
43
+ homepage: https://github.com/icatcher-at/log_me
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.9.3
54
+ none: false
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ none: false
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.23
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Simple logging functionality on a per-class basis for Rails.
67
+ test_files: []