Class ::nsmcp::LogRecordParser (public)

 ::nx::Class ::nsmcp::LogRecordParser[i]

Defined in /usr/local/ns/tcl/nsmcp/lib/log-record.tcl

Testcases:
No testcase defined.
Source code:
    :public method validRequestIdentifier {identifier} {
        # System-log identifiers are thread names, including sched/nsjob/SMTP.
        return [regexp {^-[^\x00\[\]\s]+-$} $identifier]
    }
    :public method validConnectionIdentifier {identifier} {
        return [regexp {^-conn:[^:\[\]\r\n]+:[^:\[\]\r\n]+:[0-9]+:[0-9]+-$} $identifier]
    }
    :variable colorCodeMap
    :public method stripAnsi {message} {
        if {[string first \x1b $message] < 0} {return $message}
        if {![info exists :colorCodeMap]} {
            set :colorCodeMap [list  [binary decode hex 1b5b303b33326d] {}  [binary decode hex 1b5b303b33396d] {}  [binary decode hex 1b5b306d] {}  [binary decode hex 1b5b313b33316d] {}  [binary decode hex 1b5b313b33396d] {}]
        }
        set message [string map ${:colorCodeMap} $message]
        # Preserve support for uncommon/custom SGR sequences, off the fast path.
        if {[string first \x1b $message] >= 0} {regsub -all {\x1b\[[0-9;]*m} $message {} message}
        return $message
    }
    :public method accessRequestIdentifier {message} {
        # OpenACS access format: peer request-id user [timestamp] ...
        if {[regexp {^\S+[ \t]+(\S+)[ \t]+\S+[ \t]+\[} $message -> identifier] &&
            [:validRequestIdentifier $identifier]} {
            return $identifier
        }
        return {}
    }
    :public method metadata {message} {
        # Access logs contain no ANSI formatting. Strip only system-log rows.
        if {[string index $message 0] eq "\[" || [string index $message 0] eq "\x1b"} {set message [:stripAnsi $message]}
        set result [dict create timestamp {} processThread {} logThread {}  severity {} requestIdentifier {} peerAddress {} method {} url {}  protocol {} status {} responseBytes {}]
        if {[regexp {^\[([^\]\r\n]+)\]\[([^\]\r\n]+)\]\[([^\]\r\n]+)\][ \t]+([A-Za-z][A-Za-z0-9_()-]*):[ \t]*}  $message -> timestamp processThread thread severity]} {
            dict set result timestamp $timestamp
            dict set result processThread $processThread
            dict set result logThread $thread
            dict set result severity $severity
            if {[:validRequestIdentifier $thread]} {
                dict set result requestIdentifier $thread
            }
        } elseif {[regexp {^(\S+)[ \t]+(\S+)[ \t]+\S+[ \t]+\[([0-9]{2}/[A-Za-z]{3}/[0-9]{4}:[0-9]{2}:[0-9]{2}:[0-9]{2}[ \t]+[+-][0-9]{4})\][ \t]+"((?:[^"\\\r\n]|\\.)*)"[ \t]+([1-5][0-9]{2})[ \t]+(-|[0-9]+)(?:[ \t]|$)}  $message -> peer identifier timestamp request status bytes]} {
            dict set result timestamp $timestamp
            dict set result peerAddress $peer
            if {[:validRequestIdentifier $identifier]} {dict set result requestIdentifier $identifier}
            dict set result status [scan $status %d]
            if {$bytes ne "-"} {
                set bytes [string trimleft $bytes 0]
                dict set result responseBytes [expr {$bytes eq "" ? 0 : $bytes}]
            }
            # Preserve the logged request target; do not decode percent escapes
            # or interpret the application's query parameters here.
            if {[regexp {^(\S+)[ \t]+(\S+)[ \t]+(HTTP/[0-9]+\.[0-9]+)$}  $request -> method url protocol]} {
                dict set result method $method
                dict set result url $url
                dict set result protocol $protocol
            }
        }
        if {[dict get $result status] ne "" && [nsf::object::exists ::nsmcp::accessRecordParser]} {
            set access [::nsmcp::accessRecordParser parse $message]
            foreach key {requestIdentifier method url protocol pool startTime timingSource acceptTime queueTime filterTime runTime} {
                if {[dict exists $access $key]} {dict set result $key [dict get $access $key]}
            }
        }
        return $result
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: