# File lib/phusion_passenger/debug_logging.rb, line 86
        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("%04d", now.usec / 100)

                        current_thread = Thread.current
                        if !(thread_id = current_thread[:id])
                                current_thread.to_s =~ /:(0x[0-9a-f]+)/i
                                thread_id = current_thread[:id] = $1 || '?'
                        end
                        if thread_name = current_thread[:name]
                                thread_name = "(#{thread_name})"
                        end

                        output.write("[ #{time_str} #{$$}/#{thread_id}#{thread_name} #{location} ]: #{message}\n")
                        output.flush
                end
        end