Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v diff -u -r1.140.2.41 -r1.140.2.42 --- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 26 May 2016 16:23:47 -0000 1.140.2.41 +++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 27 May 2016 08:42:20 -0000 1.140.2.42 @@ -4778,41 +4778,78 @@ return $result } -ad_proc -public ad_log { - level - message +ad_proc -public util::request_info { + {-with_headers:boolean false} } { - Output ns_log message with detailed context. This function is - intended to be used typically with "error" to ease debugging. - @param level Severity level such as "error" or "warning". - @param message Log message - + Produce a string containing the detailed request information. + This is in particular useful for debugging, when errors are raised. + + @param with_headers Include request headers @author Gustaf Neumann + } { - set request "" + set info "" if {[ns_conn isconnected]} { - append request " " \ + # + # Base information + # + append info " " \ [ns_conn method] \ " [util_current_location][ns_conn url]?[ns_conn query]" \ " referred by '[get_referrer]' peer [ad_conn peeraddr] user_id [ad_conn user_id]" - if {$level in {error Error}} { - append request \n - foreach {k v} [ns_set array [ns_conn headers]] { - append request "\n $k:\t$v" - } - if {[ns_conn method] eq "POST"} { - if {[ns_conn flags] & 1} { - append request "\n connection already closed" - } else { - set data [ns_conn content] - if {[string length $data] < 2000} { - append request "\n post-data:\t$data" + + if {[ns_conn method] eq "POST"} { + # + # POST data info + # + if {[ns_conn flags] & 1} { + append info "\n connection already closed, cooked form-content:" + foreach {k v} [ns_set array [ns_getform]] { + if {[string length $v] > 100} { + set v "[string range $v 0 100]..." } + append info "\n $k:\t$v" } + } else { + set data [ns_conn content] + if {[string length $data] < 2000} { + append info "\n post-data: $data" + } } } + + # + # Optional header info + # + if {$with_headers_p} { + append info \n + foreach {k v} [ns_set array [ns_conn headers]] { + append info "\n $k:\t$v" + } + } } + return $info +} + + + +ad_proc -public ad_log { + level + message +} { + Output ns_log message with detailed context. This function is + intended to be used typically with "error" to ease debugging. + + @param level Severity level such as "error" or "warning". + @param message Log message + + @author Gustaf Neumann +} { + set with_headers [expr {$level in {error Error}}] + append request " " \ + [util::request_info -with_headers=$with_headers] + ns_log $level "${message}\n[uplevel ad_get_tcl_call_stack]${request}\n" }