/var/www/html_de/wp-content/plugins/woocommerce/packages/blueprint/src/Logger.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php

namespace Automattic\WooCommerce\Blueprint;

use 
Automattic\WooCommerce\Blueprint\UseWPFunctions;

/**
 * Class Logger
 */
class Logger {
    use 
UseWPFunctions;

    
/**
     * WooCommerce logger class instance.
     *
     * @var \WC_Logger_Interface
     */
    
private $logger;

    
/**
     * Constructor.
     */
    
public function __construct() {
        
$this->logger wc_get_logger();
    }

    
/**
     * Log a message as a debug log entry.
     *
     * @param string $message The message to log.
     * @param string $level   The log level.
     * @param array  $context The context of the log.
     */
    
public function logstring $messagestring $level \WC_Log_Levels::DEBUG$context = array() ) {
        
$this->logger->log(
            
$level,
            
$message,
            
array_merge(
                array(
                    
'source'  => 'wc-blueprint',
                    
'user_id' => $this->wp_get_current_user_id(),
                ),
                
$context
            
)
        );
    }

    
/**
     * Log the start of an export operation.
     *
     * @param array $exporters Array of exporters.
     */
    
public function start_export( array $exporters ) {
        
$export_data $this->get_export_data$exporters );

        
$this->log(
            
sprintf'Starting export of %d steps'count$export_data['steps'] ) ),
            
\WC_Log_Levels::INFO,
            array(
                
'steps'     => $export_data['steps'],
                
'exporters' => $export_data['exporters'],
            )
        );
    }

    
/**
     * Log the completion of an export operation.
     *
     * @param array $exporters Array of exporters.
     */
    
public function complete_export( array $exporters ) {
        
$export_data $this->get_export_data$exporters );

        
$this->log(
            
sprintf'Export of %d steps completed'count$export_data['steps'] ) ),
            
\WC_Log_Levels::INFO,
            array(
                
'steps'     => $export_data['steps'],
                
'exporters' => $export_data['exporters'],
            )
        );
    }

    
/**
     * Extract export step names and exporter classes from exporters.
     *
     * @param array $exporters Array of exporters.
     * @return array Associative array with 'steps' and 'exporters' keys.
     */
    
private function get_export_data( array $exporters ) {
        
$export_steps     = array();
        
$exporter_classes = array();

        foreach ( 
$exporters as $exporter ) {
            
$step_name          method_exists$exporter'get_alias' ) ? $exporter->get_alias() : $exporter->get_step_name();
            
$export_steps[]     = $step_name;
            
$exporter_classes[] = get_class$exporter );
        }

        return array(
            
'steps'     => $export_steps,
            
'exporters' => $exporter_classes,
        );
    }

    
/**
     * Log an export step failure.
     *
     * @param string     $step_name The name of the step that failed.
     * @param \Throwable $exception The exception that was thrown.
     */
    
public function export_step_failedstring $step_name\Throwable $exception ) {
        
$this->log(
            
sprintf'Export "%s" step failed'$step_name ),
            
\WC_Log_Levels::ERROR,
            array(
                
'error' => $exception->getMessage(),
            )
        );
    }

    
/**
     * Log the start of an import step.
     *
     * @param string $step_name      The name of the step being imported.
     * @param string $importer_class The class name of the importer.
     */
    
public function start_importstring $step_namestring $importer_class ) {
        
$this->log(
            
sprintf'Starting import "%s" step'$step_name ),
            
\WC_Log_Levels::INFO,
            array(
                
'importer' => $importer_class,
            )
        );
    }

    
/**
     * Log the successful completion of an import step.
     *
     * @param string              $step_name The name of the step that was imported.
     * @param StepProcessorResult $result    The result of the import.
     */
    
public function complete_importstring $step_nameStepProcessorResult $result ) {
        
$this->log(
            
sprintf'Import "%s" step completed'$step_name ),
            
\WC_Log_Levels::INFO,
            array(
                
'messages' => $result->get_messages'info' ),
            )
        );
    }

    
/**
     * Log an import step failure.
     *
     * @param string              $step_name The name of the step that failed.
     * @param StepProcessorResult $result    The result of the import.
     */
    
public function import_step_failedstring $step_nameStepProcessorResult $result ) {
        
$this->log(
            
sprintf'Import "%s" step failed'$step_name ),
            
\WC_Log_Levels::ERROR,
            array(
                
'messages' => $result->get_messages'error' ),
            )
        );
    }
}