wpdb = $wpdb; $this->log_table = $this->wpdb->prefix . 'woocommerce_log'; parent::__construct($level, $bubble); } /** * Initializes this handler by creating the table if it not exists */ protected function initialize() { $this->initialized = true; } /** * Prepares a record that will be inserted in the audit log. * * @param array record An array of audit data. * @return array A record, ready for insertion in the audit log. */ protected function prepare_content_for_insert(array $record) { $timestamp = $record['datetime']; $insert_record = array( 'timestamp' => $timestamp->format('Y-m-d H:i:s'), 'level' => $record['level'], 'message' => $record['message'], 'source' => $record['channel'], ); $insert_record['context'] = !empty($record['context']) ? serialize($record['context']) : ''; return $insert_record; } /** * Writes the record to the audit table. * * @param array $record * @return void */ protected function write(array $record) { if(!$this->initialized) { $this->initialize(); } $format = array( '%s', '%d', '%s', '%s', '%s', // possible serialized context. ); return $this->wpdb->insert($this->log_table, $this->prepare_content_for_insert($record), $format) !== false; } }