• Resolved hanscz

    (@hanscz)


    Hey 🙂

    I am currently working on a plugin, which among other things, should log its behaviour using your excellent plugin.
    I am basing my plugin on the WordPress Plugin Boilerplate found here:
    https://github.com/devinvinson/WordPress-Plugin-Boilerplate/

    My plugin code is here: https://github.com/HansCz/tr-project-status-updater

    I load the plugin via the 'simple_history/add_custom_logger' hook in line 158, found in the file includes/class-tr-project-status-updater.php.
    This refers to load_loggers() in admin/class-tr-project-status-updater-admin.php, which looks like this:

    
      public function load_loggers($simpleHistory)
      {
        require plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-tr-project-status-updater-logger.php';
        $simpleHistory->register_logger("Tr_Project_Status_Updater_Logger_Settings");
      }
    

    In includes/class-tr-project-status-updater-logger.php things fail silently around line 86:

    $this->infoMessage("setting_updated", $context);

    Everything looks normal, however. Labels are in place in the search filter, etc.

    If I refer to SimpleLogger directly like so:
    SimpleLogger()->info($this->getInfo()["messages"]["setting_updated"], $context);

    the message logs fine.

    I would very much like to be able to filter the SimpleLogger dashboard widget to show only these messages. So from what I understand, SimpleLogger()->info(...) won’t do. I’ll have to use $this->infoMessage(...).

    It seems to fail silently somehow. Maybe you can take a look and tell me where it goes wrong?

    Thank you.

    – Hans

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter hanscz

    (@hanscz)

    I should mention that I am using Simple History version 2.13

    Thread Starter hanscz

    (@hanscz)

    Finally solved it!

    Here’s where I went wrong:
    Your custom logger class name is written to the [prefix]_simple_history table in the ‘logger’ column when you save a message.

    This column is defined as varchar(30), so your custom logger class name can be a maximum of 30 characters long, or your log message will fail to be written to the database.

    I had a class name longer than that, so

    $result = $wpdb->insert($db_table, $data);
    (line 1144 in loggers/SimpleLogger.php)

    failed silently.

    Maybe there is a way to check for that?

    Thread Starter hanscz

    (@hanscz)

    Since the issue has been resolved and described without recourse to my code, I have deleted the https://github.com/HansCz/tr-project-status-updater repository.

    Plugin Author Pär Thernström

    (@eskapism)

    Hi! Great that you solved it!

    I have had that exact problem myself and almost went nuts while trying to understand why my logger did not work. It should be some way to detect and warn about that. I’ll add it to my todo list.

    Thanks a lot for posting the solution to you problem too, so others with same problem can find this thread 🙂

    Thread Starter hanscz

    (@hanscz)

    You’re welcome 🙂

    Thread Starter hanscz

    (@hanscz)

    Incidentally, I checked up on limits to length of class names in PHP. It seems the only limit is the amount of available memory, so nothing really to help out there.

    It might be prudent to up the allowed length to, say, 255 and insert a check. If the class name is longer than the 255, maybe do an error_log()?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Custom logger: Logging fails silently’ is closed to new replies.