Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

VisitorsLogging1337

Summary: Log all activity on your wiki to a text file in a configurable way.
Version: 1.3.37
Prerequisites: none
Status: stable (works for me)
Maintainer: Piotr Szczepanski
Categories: Administration

Discussion: VisitorsLogging1337-Talk

Question

  • How can I know who is browsing/editing my wiki and where did they come from?

Answer

  • Download visitorslogging1337.phpΔ.
  • Move it to your cookbook/ directory.
  • Edit your local/config.php:
    • Insert: include_once $FarmD.'/cookbook/visitorslogging1337.php';.
    • You should edit local/farmconfig.php if you are running a WikiFarm, but you probably know that.
  • Create the directory $UploadsDir/VisitorsLog.
    • This is the default directory where the logs will be created (only if it exists)
    • This way you will be able to download them from the server.
    • Or you can define some configuration variables before the script is included (read on) to change this.

Description

This script allows you to log all activity on your wiki to a text file in a configurable way.

Default config

All the default values for variables are listed below. Copy and paste them to local/config.php, then edit there:

$VisitorsLoggingDirectory = "$UploadDir/VisitorsLog";
$VisitorsLoggingFileName = "%Y-%m-%d.txt";
$VisitorsLoggingPurgeAfterDays = 0;
$VisitorsLoggingFormat = '%Date %Time %RemoteAddr:pad %Action:pad '
    . '%HttpHost %WikiGroup.%WikiPage '
    . '"%HttpReferer" "%HttpUserAgent"' . "\n";
$VisitorsLoggingDateFormat = '%Y-%m-%d';
$VisitorsLoggingTimeFormat = '%H:%M:%S';
$VisitorsLoggingIgnoreList = array('127.0.0.1');

Description of variables

What follows is a list of supported variables along with their description:

$VisitorsLoggingDirectory

Type
string
Description
A directory on the filesystem where the logs are kept.
Defaults to
"$UploadDir/VisitorsLog"
Examples
"/tmp"
"$FarmD/admin/logs"

$VisitorsLoggingFileName

Type
string, further parsed
Description
A name for the log file
Defaults to
"%Y-%m-%d.txt"
Examples
"%Y-%j" (%j% - day of year)
"%Y-%W" gives weekly logfiles (%W - week of year)
:Note:See PHP strftime() for format reference.

$VisitorsLoggingPurgeAfterDays

Type
integer
Description
Log files will be deleted after this many days after last changed.
Defaults to
Examples
"$FarmD/admin/logs"
Note
Outdated log files are checked every time a new log file is to be created (defaults to one day).

$VisitorsLoggingFormat

Type
string
Description
See below.

$VisitorsLoggingDateFormat

Type
string, further parsed
Description
The date used for %Date in log format.
Defaults to
"%Y-%m-%d"
Note
See PHP strftime() for format reference.

$VisitorsLoggingTimeFormat

Type
string, further parsed
Description
The time used for %Time in log format.
Defaults to
"%H:%M:%S"
Note
See PHP strftime() for format reference.

$VisitorsLoggingIgnoreList

Type
array
Description
Requests from these addresses will not be logged (put your own address there).
Defaults to
array('127.0.0.1')
Example
Put something like $VisitorsLoggingIgnoreList = array(gethostbyname("www.example.com")); in local/config.php (replace www.example.com with your hostname).

Log Format Variables

The following variables in $VisitorsLoggingFormat will be substituted for their respective values:

PatternReplacement
%DateCurrent date formatted according to $VisitorsLoggingDateFormat.
%TimeCurrent time formatted according to $VisitorsLoggingTimeFormat.
%RemoteAddr= $_SERVER['REMOTE_ADDR'], IP address of the remote client
%RemoteAddr:padDitto, but padded with spaces to 15 chars.
%Action= $action, the current PmWiki action?, e.g. edit or browse.
%Action:padDitto, but padded with spaces to 8 chars.
%HttpHost= $_SERVER['HTTP_HOST'] The Host: header as sent by the client.
%HttpReferer= $_SERVER['HTTP_REFERER'] The URL of the page that sent the client here.
%HttpUserAgent= $_SERVER['HTTP_USER_AGENT'], the name of the client browser or robot
%WikiGroup= FmtPageName('$Group', $pagename) the formatted name of the requested group
%WikiPage= FmtPageName('$Name', $pagename) the formatted name of the requested page

The default log format is:

%Date %Time %RemoteAddr:pad %Action:pad %HttpHost %WikiGroup.%WikiPage "%HttpReferer" "%HttpUser
Agent\n

Substitute \n for \r\n if you want Windows-readable text files (doesn't matter if you open them only in a browser).

Notes

Limitations

Release Notes

  • 1.3.37 initial release (stable)

Comments

Use VisitorsLogging1337-Talk for discussion.

See Also

Contributors

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on September 10, 2011, at 11:42 AM