DokuWiki

It's better when it's simple

User Tools

Site Tools


tips:logging

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tips:logging [2009-03-13 08:19] – Fixed link to plugin 77.184.205.40tips:logging [2017-09-25 13:43] (current) – old revision restored (2016-02-09 08:16) bactram
Line 5: Line 5:
 I will describe two versions. The first is the high end solution and will log access to wiki pages and also to the internal and external media files. The second one is for "beginners" and will only log wiki pages. I will describe two versions. The first is the high end solution and will log access to wiki pages and also to the internal and external media files. The second one is for "beginners" and will only log wiki pages.
  
-:!: [note by J.-F. Lalande] Using the information and code provided on this page, I created the [[plugin:logstats|logstats plugin]] that generate an entry in access.log for each access of a page of dokuwiki. You can see details and download on my [[http://perso.ensi-bourges.fr/jfl/doku.php?id=wiki:logstats|logstat plugin page]]. +:!: [note by J.-F. Lalande] Using the information and code provided on this page, I created the [[plugin:logstats|logstats plugin]] that generate an entry in access.log for each access of a page of dokuwiki. You can see details and download on my [[http://sds.ensi-bourges.fr/howto/doku.php?id=wiki:logstats|logstat plugin page]].
 ===== Log File Format ===== ===== Log File Format =====
-Both solutions will use the NCSA combined or NCSA extended log file format. This log file format is very popular and often used be web servers like apache. Many report generators can read this format and create nice reports from it. Because of this fantastic support by external programs Dokuwiki doesn't need any built-in reporting functionality itself.+Both solutions will use the NCSA combined or NCSA extended log file format. This log file format is very popular and often used on web servers like apache. Many report generators can read this format and create nice reports from it. Because of this fantastic support by external programs Dokuwiki doesn't need any built-in reporting functionality itself.
  
 Report generators that could be used are (only some examples, list far from complete): Report generators that could be used are (only some examples, list far from complete):
Line 25: Line 24:
   * <request> - Requested protocol, for eg. GET or POST, requested page and protocol   * <request> - Requested protocol, for eg. GET or POST, requested page and protocol
   * <error> - error code from server, for eg. 200 (OK) or 404 (file not found)   * <error> - error code from server, for eg. 200 (OK) or 404 (file not found)
-  * <filesize> - size of the wiki page (only the bare text)+  * < filesize > - size of the wiki page (only the bare text)
   * <referer> - page from which the user come from. This information is very client dependent and not always available. The logging function does it's best to fill in useful information here.   * <referer> - page from which the user come from. This information is very client dependent and not always available. The logging function does it's best to fill in useful information here.
   * <agent> - identifying information that the client browser reports about itself   * <agent> - identifying information that the client browser reports about itself
Line 40: Line 39:
 <code php> <code php>
 function init_paths(){ function init_paths(){
-  global $conf;+    global $conf;
  
-  $paths = array('datadir'   => 'pages', +    $paths = array('datadir'   => 'pages', 
-                 'olddir'    => 'attic', +            'olddir'    => 'attic', 
-                 'mediadir'  => 'media', +            'mediadir'  => 'media', 
-                 'metadir'   => 'meta', +            'metadir'   => 'meta', 
-                 'cachedir'  => 'cache', +            'cachedir'  => 'cache', 
-                 'lockdir'   => 'locks', +            'indexdir'  => 'index', 
-                 'changelog' => 'changes.log', +            'lockdir'   => 'locks', 
-                 'accesslog' => 'access.log');+            'tmpdir   => 'tmp', 
 +            'accesslog' => 'access.log'); 
 +             
 +    foreach($paths as $c => $p){ 
 +        if(empty($conf[$c]))  $conf[$c] = $conf['savedir'].'/'.$p; 
 +        $conf[$c]             = init_path($conf[$c]); 
 +        if($c != 'accesslog' && empty($conf[$c]))  nice_die("The $c ('$p') does not exist, isn't accessible or writable. 
 +                You should check your config and permission settings. 
 +                Or maybe you want to <a href=\"install.php\">run the 
 +                installer</a>?"); 
 +    }
  
-  foreach($paths as $c => $p){ +[...]
-    if(!$conf[$c])   $conf[$c] = $conf['savedir'].'/'.$p; +
-    $conf[$c       = init_path($conf[$c]); +
-    if($c != 'accesslog' && !$conf[$c]) +
-      die("$c does not exist or isn't writable. Check config!"); +
-  } +
-}+
 </code> </code>
  
Line 65: Line 68:
  
 <code php> <code php>
-  if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/'); +if(!defined('DOKU_INC')) die('meh.'); 
-  require_once(DOKU_INC.'inc/logfile.php');   <- ADD THIS LINE +require_once(DOKU_INC.'inc/logfile.php');
-  require_once(DOKU_CONF.'dokuwiki.php');+
  
 [...] [...]
Line 84: Line 86:
 </code> </code>
  
-4. Update your favorite template to call //tpl_logfile()//. The best place is the line just after the call to //tpl_indexerWebBug()//.+4. Update your favorite template to call //tpl_logfile()//. The best place is the line just after the call to //tpl_indexerWebBug()//Most likely this is located at the end of the file main.php of your template: 
 + 
 +<code php> 
 + 
 +[...] 
 + 
 +</div> 
 +<div class="no"><?php /* provide DokuWiki housekeeping */ tpl_indexerWebBug()?></div> 
 +<div class="no"><?php /* do the logging stuff */ tpl_logfile()?></div>  <- ADD THIS LINE 
 +</body> 
 +</html> 
 + 
 +</code>
  
-5. To be able to log media files too we need to modify ///lib/exe/fetch.php//. First we need to include //inc/logfile.php// again. Add the include statement below all the others already in //lib/exe/fetch.php//. The function //logMediaAccess()// creates the log entry and need to be inserted after the media file source has been checked. A good place is near line 60 just before the existence check  (see comments below).+5. To be able to log media files too we need to modify ///lib/exe/fetch.php//. First we need to include //inc/logfile.php// again. Add the include statement below all the others already in //lib/exe/fetch.php//. The function //logMediaAccess()// creates the log entry and need to be inserted after the media file source has been checked. A good place is near <del>line 60</del> the line with the comment "%%//check file existance%%", just before the existence check  (see comments below).
  
 <code php> <code php>
Line 159: Line 173:
 Source code of //logfile.php// Source code of //logfile.php//
  
-<code php>+<code php logfile.php  
 +>
 <?php <?php
 /** /**
Line 306: Line 321:
 If you choose to use AWStats to process your logs, then here are some tips on configuration options that give you some more control over how DokuWiki accesses are shown. If you choose to use AWStats to process your logs, then here are some tips on configuration options that give you some more control over how DokuWiki accesses are shown.
  
-  * By defualt, AWStats does not keep track of the parameters after a "?" in the URL. So all your wiki accesses will appear as hits on the one page "doku.php". If you want to see which pages in the wiki are being accessed then you can enable tracking of parameters.+  * By default, AWStats does not keep track of the parameters after a "?" in the URL. So all your wiki accesses will appear as hits on the one page "doku.php". If you want to see which pages in the wiki are being accessed then you can enable tracking of parameters.
 <file> <file>
 URLWithQuery=1 # Set this to "1" to enable tracking of URL parameters URLWithQuery=1 # Set this to "1" to enable tracking of URL parameters
Line 350: Line 365:
  
 ExtraSectionName3="Wiki Searches" ExtraSectionName3="Wiki Searches"
-ExtraSectionCodeFilter3="200" +ExtraSectionCodeFilter3="200 304
-ExtraSectionCondition3="URL,\/doku.php+ExtraSectionCondition3="QUERY_STRING,do=search&id=([^&]+)
-ExtraSectionFirstColumnTitle3="Search term+ExtraSectionFirstColumnTitle3="Search terms
-ExtraSectionFirstColumnValues3="QUERY_STRING,do=search\&id=([^&]+)" +ExtraSectionFirstColumnValues3="QUERY_STRING,id=([^&]+)" 
-ExtraSectionFirstColumnFormat3="<a href="/doku.php?do=search&id=%s">%s</a>"+ExtraSectionFirstColumnFormat3="<a href="/doku.php?do=search&id=%s" target="_blank">%s</a>"
 ExtraSectionStatTypes3=PHBL ExtraSectionStatTypes3=PHBL
 ExtraSectionAddAverageRow3=0 ExtraSectionAddAverageRow3=0
-ExtraSectionAddSumRow3=1 
-MaxNbOfExtra3=10 
-MinHitExtra3=1 
 </file> </file>
 +
 +===== Discussion =====
 +Is it possible to save searches in a log file?
 +
 +I agree that that would be very helpful to be able to have in the log file rather than having to check the apache logs. Dopple 25/08/2009
  
tips/logging.1236928746.txt.gz · Last modified: 2009-07-13 10:36 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki