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

74 lines 1.6 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\Utils\Helper;
6
7 trait LogHelper {
8 private $log_types = [
9 ''
10 ];
11
12 public function sse_log( $type, $message, $progress = 1, $action = 'updateLog', $status = null ) {
13 $data = [
14 'action' => $action,
15 'type' => $type,
16 'progress' => $progress,
17 'message' => $message
18 ];
19
20 if ( $progress == 100 && $status == null ) {
21 $data['status'] = 'complete';
22 } elseif ( $status != null ) {
23 $data['status'] = $status;
24 }
25
26 $this->sse_message( $data );
27 }
28
29 public function removeLog( $type ) {
30 $this->sse_message( [
31 'action' => 'removeLog',
32 'type' => $type,
33 'progress' => 100
34 ] );
35 }
36
37 public function sse_message( $data ) {
38 // Log the data into debug log file
39 $this->debug_log( $data );
40
41 $log = get_transient( 'templately_fsi_log' ) ?: [];
42 $log[] = $data;
43 set_transient( 'templately_fsi_log', $log, 15 * MINUTE_IN_SECONDS );
44
45 if(Helper::should_flush()){
46 echo "event: message\n";
47 echo 'data: ' . wp_json_encode( $data ) . "\n\n";
48
49 // Extra padding.
50 echo esc_html( ':' . str_repeat( ' ', 2048 ) . "\n\n" );
51
52 flush();
53 }
54 else if($data['action'] === 'complete' || $data['action'] === 'downloadComplete' || $data['action'] === 'error'){
55 wp_send_json( $data );
56 }
57 }
58
59 /**
60 * Printing Error Logs in debug.log file.
61 *
62 * @param mixed $log
63 * @return void
64 */
65 public function debug_log( $log ){
66 if ( defined('TEMPLATELY_EVENT_LOG') && TEMPLATELY_EVENT_LOG === true ) {
67 if ( is_array( $log ) || is_object( $log ) ) {
68 error_log( print_r( $log, true ) );
69 } else if($log) {
70 error_log( $log );
71 }
72 }
73 }
74 }