logjam_logger 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
File without changes
data/README ADDED
@@ -0,0 +1,8 @@
1
+ This gem provides syslog-compatible logging for rails applications. It does so by monkey patching the rails logger.
2
+
3
+ User ids are logged via a global variable, $user_id. You can use a before_filter in your application_controller to set it, eg:
4
+
5
+ before_filter { |controller| $user_id = controller.session[:user_id] || 0 }
6
+
7
+ If you wish to change the format of the logged output, you can set LOGJAM_FORMATTER_CLASS to your own formatter before requiring logjam_logger.
8
+
@@ -0,0 +1,12 @@
1
+ module LogjamLogger
2
+ class Buffer < Array
3
+ def <<(message)
4
+ super formatter.format(message)
5
+ end
6
+
7
+ def formatter
8
+ klass = defined?(LOGJAM_FORMATTER_CLASS) ? LOGJAM_FORMATTER_CLASS : LogjamLogger::Formatter
9
+ @formatter ||= klass.new
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ module LogjamLogger
2
+ class Formatter
3
+ def format(message)
4
+ "#{Time.now.strftime("%b %d %H:%M:%S")} #{hostname} rails[#{$PID}]#{user_id}: #{message.gsub(/\n/, '').lstrip}\n"
5
+ end
6
+
7
+ private
8
+
9
+ # Logging user_ids via a global variable, $user_id.
10
+ # You can use a before_filter in your application_controller to set it, eg:
11
+ #
12
+ # before_filter { |controller| $user_id = controller.session[:user_id] || 0 }
13
+ def user_id
14
+ defined?($user_id) ? " user[#{$user_id}]" : ''
15
+ end
16
+
17
+ # Note: If you are using FastCGI you may need to hard-code the hostname here instead of using Socket.gethostname
18
+ def hostname
19
+ @parsed_hostname ||= Socket.gethostname.split('.').first
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ module LogjamLogger
2
+ class SimpleFormatter
3
+ def format(message)
4
+ "#{Time.now.strftime("%b %d %H:%M:%S")} rails[#{$PID}]: #{message.gsub(/\n/, '').lstrip}\n"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'logjam_logger/buffer'
2
+ require 'logjam_logger/formatter'
3
+ require 'logjam_logger/simple_formatter'
4
+
5
+ class ActiveSupport::BufferedLogger
6
+ def buffer
7
+ @buffer[Thread.current] ||= ::LogjamLogger::Buffer.new
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{logjam_logger}
3
+ s.version = "1.0.0"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["David Anderson"]
7
+ s.date = %q{2010-02-02}
8
+ s.description = %q{Syslog-compatible rails logger}
9
+ s.email = %q{david@alpinegizmo.com}
10
+ s.files = [
11
+ "LICENSE",
12
+ "README",
13
+ "logjam_logger.gemspec",
14
+ "lib/logjam_logger.rb",
15
+ "lib/logjam_logger/buffer.rb",
16
+ "lib/logjam_logger/formatter.rb",
17
+ "lib/logjam_logger/simple_formatter.rb"
18
+ ]
19
+ s.homepage = %q{http://github.com/alpinegizmo/logjam_logger}
20
+ s.rdoc_options = ["--charset=UTF-8"]
21
+ s.require_paths = ["lib"]
22
+ s.rubygems_version = %q{1.3.5}
23
+ s.summary = %q{Syslog-compatible rails logger, works well with Logjam}
24
+ s.test_files = [
25
+ ]
26
+
27
+ if s.respond_to? :specification_version then
28
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
29
+ s.specification_version = 3
30
+ else
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logjam_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - David Anderson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-02 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Syslog-compatible rails logger
17
+ email: david@alpinegizmo.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - LICENSE
26
+ - README
27
+ - logjam_logger.gemspec
28
+ - lib/logjam_logger.rb
29
+ - lib/logjam_logger/buffer.rb
30
+ - lib/logjam_logger/formatter.rb
31
+ - lib/logjam_logger/simple_formatter.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/alpinegizmo/logjam_logger
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --charset=UTF-8
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Syslog-compatible rails logger, works well with Logjam
60
+ test_files: []
61
+