PHP 8.2.31
Preview: logger.php Size: 3.43 KB
//home/nshryvcy/blissfulnepal.com/wp-content/plugins/newsletter/includes/logger.php

<?php

// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r

defined('ABSPATH') || exit;

if (!defined('NEWSLETTER_LOG_DIR')) {
    define('NEWSLETTER_LOG_DIR', WP_CONTENT_DIR . '/logs/newsletter');
}

class NewsletterLogger {

    const NONE = 0;
    const FATAL = 1;
    const ERROR = 2;
    const INFO = 3;
    const DEBUG = 4;

    static $pid = '';

    var $level;
    var $module;
    var $file;
    var $is_debug = false;
    var $offset = 0;

    function __construct($module) {
        $this->module = $module;
        if (defined('NEWSLETTER_LOG_LEVEL')) {
            $this->level = NEWSLETTER_LOG_LEVEL;
        } else {
            $this->level = (int) get_option('newsletter_log_level', self::ERROR);
        }

        $this->is_debug = $this->level == self::DEBUG;

        if (!self::$pid) {
            self::$pid = random_int(1000, 9999);
        }

        $secret = get_option('newsletter_logger_secret', '');
        if (strlen($secret) < 8) {
            $secret = NewsletterModule::get_token(8);
            update_option('newsletter_logger_secret', $secret);
        }

        if (!wp_mkdir_p(NEWSLETTER_LOG_DIR)) {
            $this->level = self::NONE;
        }

        if (is_multisite()) {

        }

        $this->file = NEWSLETTER_LOG_DIR . '/' . $module . '-' . gmdate('Y-m', time() + $this->offset) . '-' . $secret . '.txt';

        $this->offset = 3600 * (int)get_option('gmt_offset', 0);
    }

    /**
     *
     * @param string|WP_Error|array|stdClass $text
     * @param int $level
     */
    function log($text, $level = self::ERROR) {
        global $current_user;

        if ($level != self::FATAL && $this->level < $level) {
            return;
        }

        if (defined('DOING_CRON') && DOING_CRON) {
            $user = '[cron]';
        } elseif ($current_user) {
            $user = $current_user->user_login;
        } else {
            $user = '[no user]';
        }

        $time = gmdate('d-m-Y H:i:s ', time() + $this->offset);
        switch ($level) {
            case self::FATAL: $time .= '- FATAL';
                break;
            case self::ERROR: $time .= '- ERROR';
                break;
            case self::INFO: $time .= '- INFO ';
                break;
            case self::DEBUG: $time .= '- DEBUG';
                break;
        }
        if (is_wp_error($text)) {
            /* @var $text WP_Error */
            $text = $text->get_error_message() . ' (' . $text->get_error_code() . ') - ' . print_r($text->get_error_data(), true);
        } else {
            if (is_array($text) || is_object($text)) {
                $text = print_r($text, true);
            }
        }

        $memory_limit = size_format(wp_convert_hr_to_bytes(ini_get('memory_limit')));

        // The "logs" dir is created on Newsletter constructor.
        $res = @file_put_contents($this->file, $time . ' - ' . NEWSLETTER_VERSION . ' - ' . self::$pid . ' - ' . size_format(memory_get_usage(), 1) . '/' . $memory_limit . ' - ' . $user . ' > ' . $text . "\n", FILE_APPEND);
        if ($res === false) {
            //$this->level = self::NONE;
        }
    }

    function error($text) {
        self::log($text, self::ERROR);
    }

    function info($text) {
        $this->log($text, self::INFO);
    }

    function fatal($text) {
        $this->log($text, self::FATAL);
    }

    function debug($text) {
        if (!$this->is_debug) {
            return;
        }
        $this->log($text, self::DEBUG);
    }
}

Directory Contents

Dirs: 0 × Files: 27

Name Size Perms Modified Actions
5.49 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
3.64 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
1.59 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
6.43 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
12.11 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
889 B lrw-r--r-- 2026-06-03 14:57:28
Edit Download
30.01 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
1.86 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
92.78 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
1.76 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
10.24 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
2.37 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
32.76 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
15.72 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
3.43 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
11 B lrw-r--r-- 2026-06-03 14:57:28
Edit Download
21.00 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
43.63 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
43.77 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
1.26 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
4.21 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
7.71 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
8.49 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
5.79 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
9.41 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
7.26 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download
23.36 KB lrw-r--r-- 2026-06-03 14:57:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).