Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-81327

Resolve log and loglive report issues when external database are used to store logs

XMLWordPrintable

    • MOODLE_402_STABLE, MOODLE_403_STABLE, MOODLE_404_STABLE
    • MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-81327-403
    • MDL-81327-main
    • Hide

      Prerequisites

      1. Postgres or MySQL/MariaDB database 
      2. Database user details

      Testing

      1. Create a new Postgres database
        createdb -O [username] -Eutf8 mylogs
        Create a new MySQL database:
        CREATE DATABASE newlogs DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
        GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON newlogs.* TO moodleuser@'localhost';
        FLUSH PRIVILEGES;
      2. Create a new table in it (MySQL):

      CREATE TABLE `mylogs` (
        `id` bigint(10) NOT NULL AUTO_INCREMENT,
        `eventname` varchar(255) NOT NULL DEFAULT '',
        `component` varchar(100) NOT NULL DEFAULT '',
        `action` varchar(100) NOT NULL DEFAULT '',
        `target` varchar(100) NOT NULL DEFAULT '',
        `objecttable` varchar(50) DEFAULT NULL,
        `objectid` bigint(10) DEFAULT NULL,
        `crud` varchar(1) NOT NULL DEFAULT '',
        `edulevel` tinyint(1) NOT NULL,
        `contextid` bigint(10) NOT NULL,
        `contextlevel` bigint(10) NOT NULL,
        `contextinstanceid` bigint(10) NOT NULL,
        `userid` bigint(10) NOT NULL,
        `courseid` bigint(10) DEFAULT NULL,
        `relateduserid` bigint(10) DEFAULT NULL,
        `anonymous` tinyint(1) NOT NULL DEFAULT 0,
        `other` longtext DEFAULT NULL,
        `timecreated` bigint(10) NOT NULL,
        `origin` varchar(10) DEFAULT NULL,
        `ip` varchar(45) DEFAULT NULL,
        `realuserid` bigint(10) DEFAULT NULL,
        PRIMARY KEY (`id`),
        KEY `mdl_logsstanlog_tim_ix` (`timecreated`),
        KEY `mdl_logsstanlog_couanotim_ix` (`courseid`,`anonymous`,`timecreated`),
        KEY `mdl_logsstanlog_useconconcr_ix` (`userid`,`contextlevel`,`contextinstanceid`,`crud`,`edulevel`,`timecreated`),
        KEY `mdl_logsstanlog_con_ix` (`contextid`)
      ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPACT COMMENT='Standard log table external db server'; 

      Create a new table in it (postgres):

      psql mylogs
      CREATE TABLE mylogs (
          id SERIAL,
          eventname character varying(255) DEFAULT ''::character varying NOT NULL,
          component character varying(100) DEFAULT ''::character varying NOT NULL,
          action character varying(100) DEFAULT ''::character varying NOT NULL,
          target character varying(100) DEFAULT ''::character varying NOT NULL,
          objecttable character varying(50),
          objectid bigint,
          crud character varying(1) DEFAULT ''::character varying NOT NULL,
          edulevel smallint NOT NULL,
          contextid bigint NOT NULL,
          contextlevel bigint NOT NULL,
          contextinstanceid bigint NOT NULL,
          userid bigint NOT NULL,
          courseid bigint,
          relateduserid bigint,
          anonymous smallint DEFAULT 0 NOT NULL,
          other text,
          timecreated bigint NOT NULL,
          origin character varying(10),
          ip character varying(45),
          realuserid bigint
      );
      

      # Navigate to Site admin -> Plugins -> Logging -> Manage log stores

      1. Open settings for the "External database" log store
      2. Fill with:
        1. Driver: Postgresql or MySQL/MariaDB
        2. Host: Your DB host
        3. User: Your DB user
        4. Database name: mylogs
        5. Database table: mylogs
      3. Save changes
      4. Enable the store by clicking on the eye on the overview page
      5. Disable the standard log store by clicking on the eye on the overview page
      6. Browse to a course and perfrom some actions - look at the course, activities, etc.
      7. Navigate to Site admin -> Reports -> Logs
      8. Click on "Get these logs"
      9. Confirm that the logs are shown
      10. Navigate to Site admin -> Reports -> Live logs
      11. Confirm that the logs are shown{}
      Show
      Prerequisites Postgres or MySQL/MariaDB database  Database user details Testing Create a new Postgres database createdb -O [username] -Eutf8 mylogs Create a new MySQL database: CREATE DATABASE newlogs DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON newlogs.* TO moodleuser@'localhost'; FLUSH PRIVILEGES; Create a new table in it (MySQL): CREATE TABLE `mylogs` (   `id` bigint( 10 ) NOT NULL AUTO_INCREMENT,   `eventname` varchar( 255 ) NOT NULL DEFAULT '' ,   `component` varchar( 100 ) NOT NULL DEFAULT '' ,   `action` varchar( 100 ) NOT NULL DEFAULT '' ,   `target` varchar( 100 ) NOT NULL DEFAULT '' ,   `objecttable` varchar( 50 ) DEFAULT NULL,   `objectid` bigint( 10 ) DEFAULT NULL,   `crud` varchar( 1 ) NOT NULL DEFAULT '' ,   `edulevel` tinyint( 1 ) NOT NULL,   `contextid` bigint( 10 ) NOT NULL,   `contextlevel` bigint( 10 ) NOT NULL,   `contextinstanceid` bigint( 10 ) NOT NULL,   `userid` bigint( 10 ) NOT NULL,   `courseid` bigint( 10 ) DEFAULT NULL,   `relateduserid` bigint( 10 ) DEFAULT NULL,   `anonymous` tinyint( 1 ) NOT NULL DEFAULT 0 ,   `other` longtext DEFAULT NULL,   `timecreated` bigint( 10 ) NOT NULL,   `origin` varchar( 10 ) DEFAULT NULL,   `ip` varchar( 45 ) DEFAULT NULL,   `realuserid` bigint( 10 ) DEFAULT NULL,   PRIMARY KEY (`id`),   KEY `mdl_logsstanlog_tim_ix` (`timecreated`),   KEY `mdl_logsstanlog_couanotim_ix` (`courseid`,`anonymous`,`timecreated`),   KEY `mdl_logsstanlog_useconconcr_ix` (`userid`,`contextlevel`,`contextinstanceid`,`crud`,`edulevel`,`timecreated`),   KEY `mdl_logsstanlog_con_ix` (`contextid`) ) ENGINE=InnoDB AUTO_INCREMENT= 1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPACT COMMENT= 'Standard log table external db server' ; Create a new table in it (postgres): psql mylogs CREATE TABLE mylogs ( id SERIAL, eventname character varying(255) DEFAULT ''::character varying NOT NULL, component character varying(100) DEFAULT ''::character varying NOT NULL, action character varying(100) DEFAULT ''::character varying NOT NULL, target character varying(100) DEFAULT ''::character varying NOT NULL, objecttable character varying(50), objectid bigint, crud character varying(1) DEFAULT ''::character varying NOT NULL, edulevel smallint NOT NULL, contextid bigint NOT NULL, contextlevel bigint NOT NULL, contextinstanceid bigint NOT NULL, userid bigint NOT NULL, courseid bigint, relateduserid bigint, anonymous smallint DEFAULT 0 NOT NULL, other text, timecreated bigint NOT NULL, origin character varying(10), ip character varying(45), realuserid bigint ); # Navigate to Site admin -> Plugins -> Logging -> Manage log stores Open settings for the "External database" log store Fill with: Driver: Postgresql or MySQL/MariaDB Host: Your DB host User: Your DB user Database name: mylogs Database table: mylogs Save changes Enable the store by clicking on the eye on the overview page Disable the standard log store by clicking on the eye on the overview page Browse to a course and perfrom some actions - look at the course, activities, etc. Navigate to Site admin -> Reports -> Logs Click on "Get these logs" Confirm that the logs are shown Navigate to Site admin -> Reports -> Live logs Confirm that the logs are shown { }
    • HQ 2024 Sprint I1.4 Moppies

      It seams that this feature is not working with External database log (logstore_database) - the following error occurs:

      The wrong database handle is used - the table `user` cannot be found in the database `moodle_log`!

            laurent.david@moodle.com Laurent David
            melanie.treitinger@ruhr-uni-bochum.de Melanie Treitinger
            Amaia Anabitarte Amaia Anabitarte
            Huong Nguyen Huong Nguyen
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            10 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 days, 2 hours, 40 minutes
                2d 2h 40m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.