Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 98 lines (90 sloc) 3.37 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
;
; This file is part of DataBallet.
; Copyright (C) 2012 Laurent Parenteau <laurent.parenteau@gmail.com>
;
; DataBallet is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; DataBallet is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with DataBallet. If not, see <http://www.gnu.org/licenses/>.
;

start(commonfile,extfile)
;
; Start the log manager
;
new count,type,msg
do userconf^userconf
open:commonfile'="" commonfile:(append:nofixed:wrap:noreadonly:chset="M")
if extfile'="" do
. open extfile:(append:nofixed:wrap:noreadonly:chset="M")
. use extfile
. write "#Version: 1.0",!
. write "#Date: "_$zdate($horolog,"DD-MON-YEAR 24:60:SS"),!
. write "#Fields: date time bytes cached c-ip s-dns cs-method cs-uri sc-status",!
set @TMP@("DataBallet","log","count")=0
for do quit:$data(@TMP@("DataBallet","quit"))
. if '$data(@TMP@("DataBallet","log","msg")) hang 1
. else do
. . set count=$order(@TMP@("DataBallet","log","msg",""))
. . set type=$zextract(@TMP@("DataBallet","log","msg",count),1)
. . if type="c",commonfile'="" use commonfile
. . else if type="e",extfile'="" use extfile
. . else set type="skip"
. . write:type'="skip" $zextract(@TMP@("DataBallet","log","msg",count),2,$zlength(@TMP@("DataBallet","log","msg",count))),!
. . kill @TMP@("DataBallet","log","msg",count)
close:commonfile'="" commonfile
close:extfile'="" extfile
quit

log()
;
; Log the request/response
;
do common^log()
do ext^log()
quit

common()
;
; Output a Common Log Format entry for the current request/response to the log file.
;
; Common Log Format is "host ident authuser date request status bytes", with '-' for
; missing data.
;
new msg
set msg="c"_$$getcip^log()_" - - ["_$zdate(response("date"),"DD/MON/YEAR:24:60:SS ")_"+0000] """_request("method")_" "_request("uri")_" "_connection("HTTPVER")_""" "_response("status")_" "_$get(response("headers","Content-Length"),"0")
do sendmsg^log(msg)
quit

ext()
;
; Output an Extented Log Format entry for the current request/response to the log file.
;
; Extended Log Format is defined here : http://www.w3.org/TR/WD-logfile.html, but the
; exact fields used can be read in start^log().
;
new msg
set msg="e"_$zdate(response("date"),"DD-MON-YEAR 24:60:SS")_" "_$get(response("headers","Content-Length"),"0")_" "_$get(response("cached"),"0")_" "_$$getcip^log()_" "_$get(request("headers","HOST"),"*")_" "_request("method")_" "_request("uri")_" "_response("status")
do sendmsg^log(msg)
quit

sendmsg(msg)
;
; Send a msg to the log manager, maximum of 450 characters.
;
new cnt
tstart ():serial
set (cnt,@TMP@("DataBallet","log","count"))=@TMP@("DataBallet","log","count")+1
tcommit
set @TMP@("DataBallet","log","msg",cnt)=$zextract(msg,1,450)
quit

getcip()
;
; Return the IP address of the connected client
;
new devices
zshow "D":devices
quit $zpiece($zpiece(devices("D",2),"=",4),"@",1)

Something went wrong with that request. Please try again.