PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.2
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Core / Importer / LogHelper.php

LogHelper.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.2.2, at includes/Core/Importer/LogHelper.php

102 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Core\Importer;
4
5 use Templately\Core\Importer\Utils\LogHandler;
6 use Templately\Utils\Helper;
7
8 trait LogHelper {
9 private $log_types = [
10 ''
11 ];
12
13 public function sse_log( $type, $message, $progress = 1, $action = 'updateLog', $status = null ) {
14 $data = [
15 'action' => $action,
16 'type' => $type,
17 'progress' => $progress,
18 'message' => $message
19 ];
20
21 if ( $progress == 100 && $status == null ) {
22 $data['status'] = 'complete';
23 } elseif ( $status != null ) {
24 $data['status'] = $status;
25 }
26
27 $this->sse_message( $data );
28 }
29
30 public function removeLog( $type ) {
31 $this->sse_message( [
32 'action' => 'removeLog',
33 'type' => $type,
34 'progress' => 100
35 ] );
36 }
37
38 public function sse_message( $data ) {
39 // Log the data into debug log file
40 $this->sse_log_file( $data );
41
42 if(Helper::should_flush()){
43 echo "event: message\n";
44 echo 'data: ' . wp_json_encode( $data ) . "\n\n";
45
46 // Extra padding.
47 echo esc_html( ':' . str_repeat( ' ', 2048 ) . "\n\n" );
48
49 flush();
50 if (ob_get_level() > 0) {
51 ob_flush();
52 }
53 }
54 // else {
55 // $log = get_option( 'templately_fsi_log' ) ?: [];
56 // $log[] = $data;
57 // update_option( 'templately_fsi_log', $log );
58 // }
59 // else if($data['action'] === 'complete' || $data['action'] === 'downloadComplete' || $data['action'] === 'error'){
60 // wp_send_json( $data );
61 // }
62 }
63
64 /**
65 * Printing Error Logs in debug.log file or in option.
66 *
67 * @param mixed $log
68 * @return void
69 */
70 public function sse_log_file( $log ){
71 $request_params = FullSiteImport::_get_session_data();
72
73 if (is_array($log)) {
74 $log['timestamp'] = date('Y-m-d H:i:s');
75 }
76
77 if (isset($request_params['log_type']) && $request_params['log_type'] == 'file') {
78 LogHandler::sse_log_file($log);
79 } else {
80 $_log = get_option('templately_fsi_log') ?: [];
81 $_log[] = $log;
82 update_option('templately_fsi_log', $_log, false);
83 }
84 }
85 /**
86 * Printing Error Logs in debug.log file.
87 *
88 * @param mixed $log
89 * @return void
90 */
91 public function debug_log( $log ){
92 if ( defined('TEMPLATELY_EVENT_LOG') && TEMPLATELY_EVENT_LOG === true ) {
93
94 if ( is_array( $log ) || is_object( $log ) ) {
95 error_log( print_r( $log, true ) );
96 } else if($log) {
97 error_log( $log );
98 }
99
100 }
101 }
102 }