• Resolved Mikael Jokela

    (@mikael-jokela)


    Hello,

    I’m looking for a solution to log to syslog (or some other external file/database). I found the Developer Loggers plugin that should have this feature and extends the functionality of the the Simple History plugin. But the Developer Loggers plugin has not been updated for a couple of years and has an early version number.

    So I’m asking whether it is wise to start using the Developer Loggers plugin or is there a better supported way to log to syslog or other external target?

    Thank you for your help!

    Best wishes,
    Mikael

Viewing 1 replies (of 1 total)
  • Plugin Author Pär Thernström

    (@eskapism)

    The plugin should still be fine, I’m using it a a couple of places.

    It’s pretty easy to log to error log or syslog using a simple filter too, so you may use this instead if you want to (add it to your functions.php-file or similar):

    
    add_filter("simple_history/log_insert_context", "logEventsToSyslog", 10, 3);
    
    function logEventsToSyslog($context, $data, $logger)
    {
        $remote_addr = empty($context["_server_remote_addr"]) ? "" : $context["_server_remote_addr"];
        $level = empty($data["level"]) ? "" : $data["level"];
        $user_login = empty($context["_user_login"]) ? "" : $context["_user_login"];
        $message = $logger->interpolate($data["message"], $context);
    
        $log_message = sprintf(
            'WordPress Simple History: %1$s %2$s %3$s %4$s',
            $remote_addr, // 1
            $level, // 2
            $user_login, // 3
            $message // 4
        );
    
        error_log($log_message);
        syslog(LOG_INFO, $log_message);
    
        return $context;
    }
    
Viewing 1 replies (of 1 total)

The topic ‘Logging to syslog / Developer Loggers plugin’ is closed to new replies.