# woo-postnl/4.4.1/includes/class-wcpn-log.php

PostNL for WooCommerce, version 4.4.1. 56 lines.

- Page: https://pluginprobe.com/plugins/woo-postnl/4.4.1/code/includes/class-wcpn-log.php
- Raw: https://pluginprobe.com/plugins/woo-postnl/4.4.1/raw/includes/class-wcpn-log.php
- Modified: 2021-01-04T09:17:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/woo-postnl/4.4.1/code/includes/class-wcpn-log.php#L10-L20`.

```php
<?php

if (! defined('ABSPATH')) {
    exit;
} // Exit if accessed directly

if (class_exists('WCPN_Log')) {
    return;
}

class WCPN_Log
{

    /**
     * Log data if the error logging setting is enabled.
     *
     * @param string ...$messages
     */
    public static function add(string ...$messages): void
    {
        if (! WCPOST()->setting_collection->isEnabled(WCPOST_Settings::SETTING_ERROR_LOGGING)) {
            return;
        }

        $message = implode("\n", $messages);

        // Starting with WooCommerce 2.7, logging can be grouped by context and severity.
        if (class_exists("WC_Logger") && version_compare(WOOCOMMERCE_VERSION, "2.7", ">=")) {
            try {
                (wc_get_logger())->debug($message, ["source" => "wc-postnl"]);
            } catch (Exception $e) {
                exit($e);
            }
            return;
        }

        if (class_exists("WC_Logger")) {
            $wc_logger = function_exists("wc_get_logger") ? wc_get_logger() : new WC_Logger();
            $wc_logger->add("wc-postnl", $message);

            return;
        }

        // Old WC versions didn't have a logger
        // add file in upload folder - wp-content/uploads
        $upload_dir        = wp_upload_dir();
        $upload_base       = trailingslashit($upload_dir["basedir"]);
        $log_file          = $upload_base . "postnl_log.txt";
        $current_date_time = date("Y-m-d H:i:s");
        $message           = $current_date_time . " " . $message . "n";
        file_put_contents($log_file, $message, FILE_APPEND);

        return;
    }
}

```
