Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added support for Extended Log Format file. Made Common Log Format fi…

…le optional. Fixes #11
  • Loading branch information...
commit c6b01d72063461b37860af5efe7183ce6187362d 1 parent 6fd3aea
@lparenteau authored
View
2  conf/default.conf
@@ -62,6 +62,8 @@ userconf;
set conf("errorlog")="$gtm_log/databallet_error.log"
; Common Log Format file
set conf("log")="$gtm_log/databallet_access.log"
+ ; Extended Log Format file
+ set conf("extlog")="$gtm_log/databallet_extended.log"
;
; Globals configuration
;
View
1  r/caching.m
@@ -99,6 +99,7 @@
kill response
merge response=@CACHE@(host,hash)
do init^response()
+ set response("cached")=1
; Validate the client's cache.
do validatecache^request()
View
4 r/databallet.m
@@ -93,7 +93,7 @@ set conf("compressible","text/plain")=1
set conf("compressible","application/javascript")=1
; DataBallet version : YYYYMMDD
- set databalletver=20121022
+ set databalletver=20121101
quit
@@ -107,7 +107,7 @@ set conf("compressible","application/javascript")=1
; Cleanup scratch global
kill @TMP@("DataBallet")
; Start logging process
- job start^log(conf("log")):(output="/dev/null":error="/dev/null")
+ job start^log($get(conf("log"),""),$get(conf("extlog"),"")):(output="/dev/null":error="/dev/null")
new port
set port=$order(conf("listenon",""))
for quit:port="" do
View
79 r/log.m
@@ -16,33 +16,82 @@
; along with DataBallet. If not, see <http://www.gnu.org/licenses/>.
;
-start(commonfile)
+start(commonfile,extfile)
;
; Start the log manager
;
- new count
+ new count,type,msg
do userconf^userconf
- open commonfile:(append:nofixed:wrap:noreadonly:chset="M")
- use commonfile
- set @TMP@("DataBallet","commonlog","count")=0
+ 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","commonlog","msg")) hang 1
+ . if '$data(@TMP@("DataBallet","log","msg")) hang 1
. else do
- . . set count=$order(@TMP@("DataBallet","commonlog","msg",""))
- . . write @TMP@("DataBallet","commonlog","msg",count),!
- . . kill @TMP@("DataBallet","commonlog","msg",count)
- close commonfile
+ . . 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.
;
- new devices,msg,cnt
- zshow "D":devices
- set msg=$zextract($zpiece($zpiece(devices("D",2),"=",4),"@",1)_" - - ["_$zdate(response("date"),"DD/MON/YEAR:24:60:SS ")_"+0000] """_request("method")_" "_request("uri")_" "_connection("HTTPVER")_""" "_response("status")_" "_$get(response("headers","Content-Length"),"0"),1,450)
+ ; 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","commonlog","count"))=@TMP@("DataBallet","commonlog","count")+1
+ set (cnt,@TMP@("DataBallet","log","count"))=@TMP@("DataBallet","log","count")+1
tcommit
- set @TMP@("DataBallet","commonlog","msg",cnt)=msg
+ 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)
+
View
4 r/response.m
@@ -55,7 +55,7 @@ set response("status")=status
set:'$data(response("date")) response("date")=$horolog
set:'$data(request("method")) request("method")=""
set:'$data(request("uri")) request("uri")=""
- do common^log()
+ do log^log()
quit
@@ -143,7 +143,7 @@ write connection("HTTPVER")_" "_response("status")_" "_conf("status",response("s
. else do:$data(response("content")) sendcontent()
; Log request/response
- do common^log()
+ do log^log()
quit
Please sign in to comment.
Something went wrong with that request. Please try again.