/var/www/html_us/wp-content/plugins/woocommerce/src/Utilities/LoggingUtil.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
declare( strict_types=);

namespace 
Automattic\WooCommerce\Utilities;

use 
Automattic\WooCommerce\Internal\Admin\Logging\{ PageControllerSettings };
use 
Automattic\WooCommerce\Internal\Admin\Logging\FileV2\{ FileFileController };

/**
 * A class of utilities for dealing with logging.
 */
final class LoggingUtil {
    
/**
     * Get the canonical URL for the Logs tab of the Status admin page.
     *
     * @return string
     */
    
public static function get_logs_tab_url(): string {
        return 
wc_get_container()->getPageController::class )->get_logs_tab_url();
    }

    
/**
     * Determine the current value of the logging_enabled setting.
     *
     * @return bool
     */
    
public static function logging_is_enabled(): bool {
        return 
wc_get_container()->getSettings::class )->logging_is_enabled();
    }

    
/**
     * Determine the current value of the default_handler setting.
     *
     * @return string
     */
    
public static function get_default_handler(): string {
        return 
wc_get_container()->getSettings::class )->get_default_handler();
    }

    
/**
     * Determine the current value of the retention_period_days setting.
     *
     * @return int
     */
    
public static function get_retention_period(): int {
        return 
wc_get_container()->getSettings::class )->get_retention_period();
    }

    
/**
     * Determine the current value of the level_threshold setting.
     *
     * @return string
     */
    
public static function get_level_threshold(): string {
        return 
wc_get_container()->getSettings::class )->get_level_threshold();
    }

    
/**
     * Generate a public ID for a log file based on its properties.
     *
     * The file ID is the basename of the file without the hash part. It allows us to identify a file without revealing
     * its full name in the filesystem, so that it's difficult to access the file directly with an HTTP request.
     *
     * @param string   $source   The source of the log entries contained in the file.
     * @param int|null $rotation Optional. The 0-based incremental rotation marker, if the file has been rotated.
     *                           Should only be a single digit.
     * @param int      $created  Optional. The date the file was created, as a Unix timestamp.
     *
     * @return string
     */
    
public static function generate_log_file_idstring $source, ?int $rotation nullint $created ): string {
        return 
File::generate_file_id$source$rotation$created );
    }

    
/**
     * Generate a hash to use as the suffix on a log filename.
     *
     * @param string $file_id A file ID (file basename without the hash).
     *
     * @return string
     */
    
public static function generate_log_file_hashstring $file_id ): string {
        return 
File::generate_hash$file_id );
    }

    
/**
     * Get the directory for storing log files.
     *
     * @param bool $create_dir Optional. True to attempt to create the log directory if it doesn't exist. Default true.
     *
     * @return string The full directory path, with trailing slash.
     */
    
public static function get_log_directorybool $create_dir true ): string {
        return 
Settings::get_log_directory$create_dir );
    }

    
/**
     * Calculate the size, in bytes, of the log directory.
     *
     * @return int
     */
    
public static function get_log_directory_size(): int {
        return 
wc_get_container()->getFileController::class )->get_log_directory_size();
    }
}