Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Logging API: Difference between revisions

From MoodleDocs
No edit summary
Line 1: Line 1:
This page is under development
==Overview==
==Overview==
The Logging API allows you to add new entries to the Moodle log and define how they get displayed in reports. Logging is an extremely important and often neglected aspect of Moodle Plugin development. All important actions such as viewing, deleting, editing etc should be logged.


==File locations==
==File locations==
Line 6: Line 9:


==Functions and Examples==
==Functions and Examples==
===Functions===


Following are the functions that constitute the basic log API for Moodle.
<code>
<code>
  function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0)
  add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0)
  function user_accesstime_log($courseid=0)
  user_accesstime_log($courseid=0)
  get_logs($select, array $params=null, $order='l.time DESC', $limitfrom='', $limitnum='', &$totalcount)
  get_logs($select, array $params=null, $order='l.time DESC', $limitfrom='', $limitnum='', &$totalcount)
  function get_logs_usercourse($userid, $courseid, $coursestart)
  get_logs_usercourse($userid, $courseid, $coursestart)
  function get_logs_userday($userid, $courseid, $daystart)
  get_logs_userday($userid, $courseid, $daystart)
</code>
</code>
The basic working of these functions can be categorized in two categories:-
# Adding data to logs
# Fetching data from logs
Let us take a deeper look into both of these:-
===Adding data to Logs===
In Moodle basically we have two functions that take care of adding data to the logs table:-
<code>
add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0)
user_accesstime_log($courseid=0)
</code>
==== add_to_log() ====
This function is basic core function which you should use to add all your logs to the Moodle Log table. While using this function to add data to logs, please remeber that this function is more of "Action" oriented stuff rather than being based on "webserver hits", i.e the events should be logged with enough information that this data can be effectively used to regenerate the entire flow of events and action associated with any specific user.


===Examples===
==== user_accesstime_log() ====


===Fetching Logs===
====get_logs()====
====get_logs_usercourse()====
====get_logs_userday()====
==Mod/*/db/log.php Files==
==Mod/*/db/log.php Files==
===Example===
===Example===
Line 24: Line 45:
==See Also==
==See Also==
[https://docs.moodle.org/22/en/Logs Logs Reports]
[https://docs.moodle.org/22/en/Logs Logs Reports]
The Logging API allows you to add new entries to the Moodle log and define how they get displayed in reports.
(Ankit, please describe how the db/log.php files work too)

Revision as of 06:35, 12 January 2012

This page is under development

Overview

The Logging API allows you to add new entries to the Moodle log and define how they get displayed in reports. Logging is an extremely important and often neglected aspect of Moodle Plugin development. All important actions such as viewing, deleting, editing etc should be logged.

File locations

The Log API is all in lib/datalib.php and is automatically included for you during the page setup.

Functions and Examples

Following are the functions that constitute the basic log API for Moodle.

add_to_log($courseid, $module, $action, $url=, $info=, $cm=0, $user=0)
user_accesstime_log($courseid=0)
get_logs($select, array $params=null, $order='l.time DESC', $limitfrom=, $limitnum=, &$totalcount)
get_logs_usercourse($userid, $courseid, $coursestart)
get_logs_userday($userid, $courseid, $daystart)

The basic working of these functions can be categorized in two categories:-

  1. Adding data to logs
  2. Fetching data from logs

Let us take a deeper look into both of these:-

Adding data to Logs

In Moodle basically we have two functions that take care of adding data to the logs table:-

add_to_log($courseid, $module, $action, $url=, $info=, $cm=0, $user=0)
user_accesstime_log($courseid=0)

add_to_log()

This function is basic core function which you should use to add all your logs to the Moodle Log table. While using this function to add data to logs, please remeber that this function is more of "Action" oriented stuff rather than being based on "webserver hits", i.e the events should be logged with enough information that this data can be effectively used to regenerate the entire flow of events and action associated with any specific user.

user_accesstime_log()

Fetching Logs

get_logs()

get_logs_usercourse()

get_logs_userday()

Mod/*/db/log.php Files

Example

See Also

Logs Reports