PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.2.6
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.2.6
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.6, at includes/Core/Importer/LogHelper.php

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