Module: PhusionPassenger::DebugLogging

Included in:
AbstractRequestHandler, ClassicRails::ApplicationSpawner, Rack::ApplicationSpawner
Defined in:
lib/phusion_passenger/debug_logging.rb

Constant Summary collapse

@@log_level =

We don’t refer to STDERR directly because STDERR’s reference might change during runtime.

0
@@log_device =
nil
@@log_filename =
nil
@@stderr_evaluator =
lambda { STDERR }

Class Method Summary collapse

Class Method Details

._log_deviceObject



55
56
57
# File 'lib/phusion_passenger/debug_logging.rb', line 55

def self._log_device
	return @@log_device
end

.debug(message) ⇒ Object



77
78
79
# File 'lib/phusion_passenger/debug_logging.rb', line 77

def debug(message)
	trace(1, message, 1)
end

.error(message) ⇒ Object



67
68
69
# File 'lib/phusion_passenger/debug_logging.rb', line 67

def error(message)
	trace(-1, message, 1)
end

.included(klass) ⇒ Object



34
35
36
37
38
39
# File 'lib/phusion_passenger/debug_logging.rb', line 34

def self.included(klass)
	klass.class_eval do
		private :debug
		private :trace
	end
end

.log_file=(filename) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/phusion_passenger/debug_logging.rb', line 45

def self.log_file=(filename)
	if filename && filename.empty?
		@@log_filename = nil
	else
		@@log_filename = filename
	end
	@@log_device.close if @@log_device && !@@log_device.closed?
	@@log_device = nil
end

.log_level=(level) ⇒ Object



41
42
43
# File 'lib/phusion_passenger/debug_logging.rb', line 41

def self.log_level=(level)
	@@log_level = level
end

.stderr_evaluator=(block) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/phusion_passenger/debug_logging.rb', line 59

def self.stderr_evaluator=(block)
	if block
		@@stderr_evaluator = block
	else
		@@stderr_evaluator = lambda { STDERR }
	end
end

.trace(level, message, nesting_level = 0) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/phusion_passenger/debug_logging.rb', line 82

def trace(level, message, nesting_level = 0)
	if @@log_level >= level
		if @@log_filename
			if !@@log_device || @@log_device.closed?
				@@log_device = File.open(@@log_filename, "a")
			end
			output = @@log_device
		else
			output = @@stderr_evaluator.call
		end
		location = caller[nesting_level].sub(/.*phusion_passenger\//, '')
		location.sub!(/(.*):.*/, '\1')
		now = Time.now
		time_str = now.strftime("%Y-%m-%d %H:%M:%S.")
		time_str << sprintf("%03d", now.usec / 1000)
		output.write("[ pid=#{$$} thr=#{Thread.current.object_id} file=#{location} time=#{time_str} ]: #{message}\n")
		output.flush
	end
end

.warn(message) ⇒ Object



72
73
74
# File 'lib/phusion_passenger/debug_logging.rb', line 72

def warn(message)
	trace(0, message, 1)
end