bonny / WordPress-Simple-History

🔍🕵️‍♀️ WordPress audit log that track user changes in WordPress admin using a nice activity feed.
https://simple-history.com
311 stars 69 forks source link

Adding other log storage destinations? #114

Open jschumann opened 8 years ago

jschumann commented 8 years ago

Would you be open to adding additional log storage/aggregation services?

I would find it valuable to be able to log events to a central location like a Syslog server or a Logging as a Service provider, and I don't think I'm alone.

In the same way that your plugin can currently be extended to include additional loggers, it could probably be reworked to allow for including additional log storage backends. (With the assumption that it still ships with the local storage option as a default.)

I was about to fork your repo and start replacing the local storage component(s), (and ripping out the UI, which I won't need if logs are stored elsewhere) but then I figured that if you're open to this, then I could instead try to make the log storage modular. Or at least write another storage component as an addition, rather than a replacement, and hand that back to you. I really like everything else about Simple History, and I don't want to have to maintain a duplicate of 90% of it just to send my logs elsewhere.

Let me know. Thanks!

ajoah commented 7 years ago

@bonny Do you have a opinion about this feature? Centralizing logs could be awesome :heart_eyes:

viktorix commented 5 years ago

+1

dfinnema commented 4 years ago

Looks like this is already possible, using the action 'simple_history/log/inserted' (see below).

@param array $context Array with all context data that was used to log event. @param array $data Array with data used for parent row. @param array $this Reference to this logger instance do_action( 'simple_history/log/inserted', $context, $data_parent_row, $this);

See Line 1467 in loggers/SimpleLogger.php

Smig0l commented 8 months ago

add after: simple-history/loggers/class-logger.php#L1307

                 /**
         * CUSTOMIZED/HARDCODED PLUGIN EDIT. FIXME: WILL BE OVERRIDEN WHEN THE PLUGIN IS UPDATED!!
         * 
         */
        /* append to /etc/rsyslog.d/ext-syslog.conf:
            $ModLoad imfile
            $InputFileName /var/www/html/site/wp-content/themes/childtheme/simplehistory_tmp.log
            $InputFileTag simplehistory_wp:
            $InputFileStateFile simplehistory_wp-statefile
            $InputFileFacility local7
            $InputRunFileMonitor
            if $programname == 'simplehistory_wp' then @syslogserver:514
        */
        //Extract specific keys from $context
        $log_context = [
            '_message_key' => isset($context['_message_key']) ? $context['_message_key'] : '',
            '_user_email' => isset($context['_user_email']) ? $context['_user_email'] : '',
            '_server_remote_addr' => isset($context['_server_remote_addr']) ? $context['_server_remote_addr'] : '',
            '_server_http_referer' => isset($context['_server_http_referer']) ? $context['_server_http_referer'] : '',
        ];
        // Create log message with timestamp and extracted context
        $log_entry = date('[Y-m-d H:i:s]') . " [$level] $message, DETAILS: " . implode(', ', $log_context) . PHP_EOL;
        // Path to the log file
        $log_file = get_template_directory() . '/simplehistory_tmp.log';
        // Write log message to file
        file_put_contents($log_file, $log_entry, FILE_APPEND | LOCK_EX);
        //END

be careful. this is a fast way to add syslog functionality. it will be overwritten when the plugin updates.

bonny commented 1 day ago

Related: #184