Usage
nebula()->add_log($message, $importance)
Parameters
$message
(Required) (String) The message text
Default: None
$importance
(Optional) (Integer) How important this log is (0-10)
Default: None
Parameter Notes
Do not include personally identifiable information in the message. This log database is meant for strictly administrative events– this is not meant to log visitor usage data or personal information!
Logs with an importance of 0 may be automatically removed to save space in the log database.
Note: A timestamp is automatically added to the message as well as the user who logged the message (so those are not needed in the message string).
Additional Notes
This log option is disabled by default! It will not log anything when disabled, so retroactive logs are not possible. It is available in Nebula Options in the Administrative tab and logs themselves can be viewed in Nebula Options in the Diagnostics tab.
Some examples of administrative events that are logged by Nebula itself:
- Nebula theme activation
- Nebula theme updates (via WordPress updater)
- WordPress core updates (via WordPress updater)
- Nebula Options saved
- Admin user registration
- Automatic Sass disabling
Source File
Located in /libs/Utilities/Logs.php on line 200.
2 Hooks
Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.
Filters
This function has no filter hooks available. Request one?
Actions
"qm/error""qm/info"
Need a new action hook? Request one here.
Note: This function contains 1 to-do comment.
public function add_log($message='', $importance=0, $optimize=true){
if ( $this->is_minimal_mode() ){return null;}
if ( !is_user_logged_in() || empty($message) ){
return null;
}
$this->timer('Add Log to Table', 'start', '[Nebula] Logs');
//Add the log to the Sucuri audit log if the plugin is being used
if ( class_exists('SucuriScanEvent') && method_exists('SucuriScanEvent', 'reportInfoEvent') ){ //Check if the Sucuri class and one of the log functions exists
SucuriScanEvent::reportInfoEvent($message);
}
if ( $this->get_option('administrative_log') ){ //If the Nebula Option is enabled
global $wpdb;
$log_inserted = $wpdb->insert($wpdb->nebula_logs, array(
'timestamp' => intval(date('U')),
'message' => sanitize_text_field($message),
'user_id' => intval(get_current_user_id()), //Note: returns 0 in cron jobs
'importance' => intval($importance)
)); //DB Query
if ( $log_inserted === false ){ //This could happen if the option was enabled (somehow) by non-staff, and a log was attempted to be added
$this->update_option('administrative_log', 0); //Disable the option just to be safe. Unfortunately this cannot be logged somewhere...
do_action('qm/error', 'Failed to insert log into database.');
$this->timer('Add Log to Table', 'end');
return false; //Log entry was not inserted
}
delete_transient('nebula_logs');
do_action('qm/info', 'Added Nebula Log: ' . sanitize_text_field($message));
/*
if ( !empty($optimize) ){
//$this->optimize_logs(); //@todo "nebula" 0: Need to test this before enabling!
}
*/
if ( $this->is_debug(false) || WP_DEBUG || WP_DEBUG_LOG ){
$user = get_userdata(intval(get_current_user_id()));
$user_name = ( $user )? $user->display_name : 'Unknown';
$this->debug_log($message . ' [User: ' . $user_name . ']'); //Log the message to a file too when debug mode is active
}
$this->timer('Add Log to Table', 'end');
return true; //Log entry was inserted
}
$this->timer('Add Log to Table', 'end');
return null;
}
Override
This function can not be short-circuited with an override filter. Request one?