Monday, November 08, 2010 at 12:05 AM.

system.verbs.builtins.radio.log.addToServerLog

on addToServerLog (pta) {
	<<Changes
		<<11/5/01; 12:07:53 AM by JES
			<<Ported from suites.playlist.addToServerLog.
		<<Changes before 11/5/01
			<<07/26/00; 3:18:19 PM by PBS
				<<Created. Add an entry to the top of the server log outline.
			<<Thursday, July 27, 2000 at 3:16:59 PM by DW
				<<Add a space before the time if it's between 1AM and 9AM or 1PM and 9PM.
			<<1/25/01; 5:07:53 PM by DW
				<<Rewrite. Log to the daily log database. 
				<<Old version is archived below.
					<<
						<<local (adrLog = @user.webserver.stats.log)
						<<local (oldTarget = target.set (adrLog))
						<<
						<<op.firstSummit ()
						<<
						<<local (s)
						<<local (url = string.nthField (pta^.firstLine, ' ', 2))
						<<local (client = tcp.dns.getDomainName (pta^.client))
						<<
						<<local (timestring)
						<<bundle //set timestring
							<<local (now = clock.now ())
							<<timestring = string.timeString (now)
							<<local (day, month, year, hour, minute, second)
							<<date.get (now, @day, @month, @year, @hour, @minute, @second)
							<<if ((hour >= 1) and (hour <= 9)) or ((hour >= 13) and (hour <= 21))
								<<timestring = " " + timestring
						<<
						<<s = timestring + " - " + url + " - " + pta^.code + " - " + client
						<<if defined (pta^.f) //was a file served?
							<<local (fileSize = file.size (pta^.f))
							<<s = s + " - " + fileSize 
						<<
						<<if (sizeOf (adrLog^) == 1) and (op.getLineText () == "") //is it an empty outline?
							<<op.setLineText (s)
						<<else
							<<op.insert (s, up)
						<<
						<<try {target.set (oldTarget)}
						<<
						<<return (true)
			<<1/26/01; 6:49:17 AM by DW
				<<On redirects Content-Type is not set, so if it's not defined we set it to the empty string.
			<<2/20/01; 3:49:33 PM by PBS
				<<Neuter potential JavaScript and curly braces in uri and client, since these items get displayed on the Web server log page.
	on untaint (s) {
		s = string.replaceAll (s, "{", "&123;"); //no curly brace macros
		s = html.neuterJavaScript (s); //no JavaScript
		return (s)};
	
	local (adrtable = log.addToGuestDatabase ("webServer", flHourlyRoll:true));
	adrtable^.uri = untaint (pta^.uri); //PBS 02/20/01: neuter
	adrtable^.client = untaint (pta^.client); //PBS 02/20/01: neuter
	adrtable^.code = pta^.code;
	adrtable^.size = sizeof (pta^.responseBody);
	bundle { //set secs
		local (s = string (double (clock.ticks () - pta^.stats.requestProcessingStarted) / 60));
		local (lod = string.nthfield (s, ".", 1));
		local (rod = string.nthfield (s, ".", 2));
		if sizeof (rod) > 3 {
			rod = string.mid (rod, 1, 3)}
		else {
			if sizeof (rod) < 3 {
				rod = string.padwithzeros (rod, 3)}};
		adrtable^.secs = lod + "." + rod};
	if defined (pta^.responseHeaders.["Content-Type"]) {
		adrtable^.type = pta^.responseHeaders.["Content-Type"]}
	else {
		adrtable^.type = ""};
	return (true)}
<<bundle //test code
	<<addToServerLog (@["1/25/2001"].webServer.["17"].["00001000\t1/25/2001; 5:15:24 PM"].paramtable)



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.