DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

tips:tinylogging

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.


It is working well and the performance impact is very small. Two things I want to mention here.
There may be a conflict of permissions in the event webserver and DW admin are not at the same group.
Apache creates the log with permissions 0770 (independently what was set at DW configuration) and the
DW admin is not able to read or delete the log.

You could add after the last line of code following:

  chmod($filename; 0777);

Another point to be considered is that the log file is growing a bit uncontrolled.
Depending on the usage of DW it will increase rapidly. Probably you can add a check
on a threhold (e.g. file size, quantity of text lines, etc.) to clean up the file. Keep it fast and simple.

Taggic, 2011-01-27
tips/tinylogging.txt · Last modified: 2011-03-01 14:32 by 192.100.123.77