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

system.verbs.builtins.mainResponder.log.browser

on browser (linecount, colors) { //a macro that returns HTML for the log
	<<Changes:
		<<4/14/00; 5:28:17 PM by JES
			<<localized
	local (adrlog = log.getGuestSubTable ("mainResponder"));
	linecount = number (linecount); //I keep getting bit by this, when called thru a macro, it's a string DW
	
	local (htmltext = "", indentlevel = 0);
	on add (s) {
		htmltext = htmltext + string.filledString ("\t", indentlevel) + s + "\r"};
	on td (s) {
		return ("<td><font size=\"-1\">" + s + "</font></td>")};
	
	if not config.mainresponder.prefs.flLog {
		add (mainResponder.getString ("log.loggingIsDisabled")); // 4/14/00 JES: localized
		return (htmltext)};
	
	local (i, j, adrhourtable, adritem, sizelog = sizeof (adrlog^), ixlog, sizehourtable);
	add ("<table width=\"92%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"); indentlevel++;
	
	adrhourtable = @adrlog^ [sizelog]; //generate for the most recent hour
	sizehourtable = sizeof (adrhourtable^);
	ixlog = sizehourtable - linecount + 1;
	if ixlog < 1 {
		ixlog = 1};
	for j = sizehourtable downto ixlog {
		adritem = @adrhourtable^ [j];
		add ("<!-- " + j + " -->");
		if defined (adritem^.htmlcache) {
			local (oldindentlevel = indentlevel);
			indentlevel = 0;
			add (adritem^.htmlcache);
			indentlevel = oldindentlevel}
		else {
			local (ixhtmltext = sizeof (htmltext));
			add ("<tr bgcolor=\"" + colors [(j % sizeof (colors)) + 1] + "\">"); indentlevel++;
			add ("<td height=\"28\"></td>"); //a dummy table cell to establish row height
			with adritem^ {
				local (ticksstring = "");
				try { //get ticks, expressed in a fraction of a second, it's complicated
					ticksstring = string.ratio (ticks, 60, 2);
					if ticks > 120 { //more than two seconds
						ticksstring = "<b><font color=\"deeppink\">" + ticksstring + "</font></b>"}};
				add (td (string.popLeading (string.nthField (time, ";", 2), ' ')));
				add (td (code));
				add (td (" " + threads + " "));
				add (td (" " + ticksstring+ " "));
				add (td (string.megabytestring (size)));
				bundle { //add the member name, if we have it, otherwise do a DNS lookup
					if defined (member) {
						local (groupname = config.mainResponder.globals.defaultMembershipGroup);
						local (link = mainResponder.members.linktomember (groupname, adritem^.member));
						add (td (link))}
					else {
						local (client = xml.convertToDisplayName (nameof (adritem^)));
						try {client = tcp.dns.getDomainName (client)};
						add (td (client))}};
				bundle { //add the link
					local (link = "http://");
					if defined (host) {
						link = link + host}
					else {
						link = link + tcp.dns.getMyDomainName ()};
					link = link + url;
					if defined (pathargs) {
						if pathargs != "" {
							link = link + "$" + pathargs}};
					if defined (searchargs) {
						if searchargs != "" {
							link = link + "?" + searchargs}};
					add (td ("<a href=\"" + link + "\">" + url + "</a>"))};
				<<bundle //add the host
					<<if defined (host)
						<<add (td (host))
					<<else
						<<add (td (" "))
				bundle { //add the referrer
					if defined (referrer) {
						add (td ("<a href=\"" + referrer + "\">*</a>"))}
					else {
						add (td (" "))}}};
			add ("</tr>"); indentlevel--;
			
			adritem^.htmlcache = string.delete (htmltext, 1, ixhtmltext);
			adritem^.htmlcache = string.delete (adritem^.htmlcache, sizeof (adritem^.htmlcache), 1)}};
		<<linecount--
		<<if linecount <= 0
			<<break
	
	<<for ixlog = sizelog downto 1
		<<adrhourtable = @adrlog^ [ixlog] //generate in reverse-chronologic order
		<<for j = sizeof (adrhourtable^) downto 1
	
	add ("</table>"); indentlevel--;
	
	return (htmltext)};
bundle { //test code
	browser (25, {"cornflowerblue", "papayawhip"})}



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.