PluginProbe
YayMail – WooCommerce Email Customizer / 2.1.5
YayMail – WooCommerce Email Customizer v2.1.5
4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 All 57 releases
yaymail / includes / Helper / LogHelper.php

LogHelper.php in YayMail – WooCommerce Email Customizer 2.1.5, at includes/Helper/LogHelper.php

82 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Helper;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class LogHelper {
8
9 public static function writeLog( $message, $type_log = 'error', $name = 'log' ) {
10 if ( ! is_string( $message ) ) {
11 $message = print_r( $message, true );
12 }
13
14 $folder = YAYMAIL_PLUGIN_PATH . '/includes/Logs';
15 if ( ! file_exists( $folder ) ) {
16 @mkdir( $folder, 0755 );
17 @chmod( $folder, 0755 );
18
19 }
20
21 $filename = $folder . DIRECTORY_SEPARATOR . $name . '.txt';
22
23 clearstatcache(); // Remove filesize cache
24
25 $handle = fopen( $filename, 'a' );
26 if ( filesize( $filename ) == 0 ) {
27 fwrite( $handle, self::getSystemStats() );
28 }
29
30 fwrite( $handle, current_time( 'mysql' ) . ' [' . strtoupper( $type_log ) . '] ' . $message . PHP_EOL );
31 fclose( $handle );
32 }
33 private static function getSystemStats() {
34 global $wpdb;
35
36 if ( ! function_exists( 'get_plugins' ) ) {
37 include_once ABSPATH . 'wp-admin/includes/plugin.php';
38 }
39 $server_software = isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( $_SERVER['SERVER_SOFTWARE'] ) : '';
40 $system_stats = '==== SYSTEM STATS ====' . PHP_EOL;
41 $system_stats .= 'WordPress Version: ' . get_bloginfo( 'version' ) . PHP_EOL;
42 $system_stats .= 'PHP Version: ' . phpversion() . PHP_EOL;
43 $system_stats .= 'MySQL Version: ' . $wpdb->db_version() . PHP_EOL;
44 $system_stats .= 'Website Name: ' . get_bloginfo() . PHP_EOL;
45 $system_stats .= 'Theme: ' . wp_get_theme() . PHP_EOL;
46 $system_stats .= 'WordPress URL: ' . site_url() . PHP_EOL;
47 $system_stats .= 'Site URL: ' . home_url() . PHP_EOL;
48 $system_stats .= 'Multisite: ' . ( is_multisite() ? 'yes' : 'no' ) . PHP_EOL;
49 $system_stats .= 'PHP Extensions: ' . json_encode( get_loaded_extensions() ) . PHP_EOL;
50 $system_stats .= 'Server Info: ' . $server_software . PHP_EOL;
51 $system_stats .= 'WP Memory Limit: ' . WP_MEMORY_LIMIT . PHP_EOL;
52 $system_stats .= 'WP Admin Memory Limit: ' . WP_MAX_MEMORY_LIMIT . PHP_EOL;
53 $system_stats .= 'PHP Memory Limit: ' . ini_get( 'memory_limit' ) . PHP_EOL;
54 $system_stats .= 'Max Execution Time: ' . ini_get( 'max_execution_time' ) . PHP_EOL;
55 $system_stats .= 'Open BaseDir: ' . ini_get( 'open_basedir' ) . PHP_EOL;
56 $system_stats .= 'WordPress Plugins: ' . json_encode( get_plugins() ) . PHP_EOL;
57 $system_stats .= 'WordPress Active Plugins: ' . json_encode( get_site_option( 'active_plugins' ) ) . PHP_EOL;
58 $system_stats .= '==== SYSTEM STATS ====' . PHP_EOL . PHP_EOL;
59 return $system_stats;
60 }
61 public static function getMessageException( $ex, $ajax = false ) {
62 $message = 'SYSTEM ERROR: ' . $ex->getCode() . ' : ' . $ex->getMessage();
63 $message .= PHP_EOL . $ex->getFile() . '(' . $ex->getLine() . ')';
64 $message .= PHP_EOL . $ex->getTraceAsString();
65 self::writeLog( $message );
66 if ( $ajax ) {
67 wp_send_json_error( array( 'mess' => $message ) );
68 }
69
70 }
71
72 // writeLog use show content when save email, save
73 public static function writeLogContent( $content = '', $tailName = 'html' ) {
74 $name = 'log-' . current_time( 'timestamp' );
75 $folder = YAYMAIL_PLUGIN_PATH . '/includes/Logs';
76 $filename = $folder . DIRECTORY_SEPARATOR . $name . '.' . $tailName;
77 $handle = fopen( $filename, 'a' );
78 fwrite( $handle, print_r( $content, true ) );
79 fclose( $handle );
80 }
81 }
82