Open jschumann opened 8 years ago
@bonny Do you have a opinion about this feature? Centralizing logs could be awesome :heart_eyes:
+1
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
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.
Related: #184
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!