Skip to Content

add_log()

Add an entry to the Nebula administrative log.

PHP May 1, 2020

Usage

PHP
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).

Request or provide clarification »

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 56.

No Hooks

This function does not have any filters or actions available. Request one?

Note: This function contains 1 to-do comment.

PHP
        public function add_log($message='', $importance=0, $optimize=true){
            if ( $this->get_option('logs') && $this->is_staff() && !empty($message) ){
                global $wpdb;

                $wpdb->insert($wpdb->nebula_logs, array(
                    'timestamp' => sanitize_text_field(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

                delete_transient('nebula_logs');

/*
                if ( !empty($optimize) ){
                    //$this->optimize_logs(); //@todo "nebula" 0: Need to test this before enabling!
                }
*/
            }

            return false;
        }

Override

This function can not be short-circuited with an override filter. Request one?