Translations of this page?:
Table of Contents

Tiny logging

Once a year I have to make some stats on activity per user, types of action, and the pages/namespaces that are hot.

For this I include a short php snippet in the footer of the template.

It will write the following details to a logfile.

  • date
  • year
  • month
  • day
  • user (if logged in)
  • namespace:page
  • type of action

Its fast and easy to read this file into e.g. Excel and analyse it for example with Pivot tables.

I use jpgraph to make images on the fly.

Use it

  1. Create file in the template directory, called log.txt and make it writeable
  2. Include code below in the footer of your template
$filename =dirname(__FILE__).'/log.txt';
$timestamp = date("Y:m:d:H:i:s");
$user = $_SERVER['REMOTE_USER'];
$id=addslashes($_GET["id"]);
$id.=addslashes($_POST["id"]);
$action=addslashes($_POST["do"]);
$action.=addslashes($_GET["do"]);
$logentry=date("Y")."|".date("m")."|".date("d")."|".$timestamp."|".$user."|".$action."|".$id."\r\n";
if (!$handle = fopen($filename, 'a')) {exit;}
if (fwrite($handle, $logentry) === FALSE) {exit; }
fclose($handle);

Discussion

As said, this is a quick and dirty way to collect rudimentary statistics.

 
tips/tinylogging.txt · Last modified: 2008/07/23 09:36 by 83.98.240.212
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate