| 1 |
<?php |
| 2 |
|
| 3 |
namespace Bookit\Helpers; |
| 4 |
|
| 5 |
use Google\Exception; |
| 6 |
|
| 7 |
/** |
| 8 |
* Bookit Log Helper |
| 9 |
*/ |
| 10 |
|
| 11 |
define( 'BOOKIT_LOG_PATH', realpath(__DIR__ . '/..' . '/..') . '/logs/' ); |
| 12 |
|
| 13 |
class LogHelper { |
| 14 |
|
| 15 |
public static function writeLogs( $fileName, $args ) { |
| 16 |
$data = date("Y-m-d H:i:s") . "\n"; |
| 17 |
$data .= "DEBUG DATA:\n"; |
| 18 |
$data .= json_encode(debug_backtrace(false, 2)) . "\n"; |
| 19 |
|
| 20 |
$data .= "DATA:\n"; |
| 21 |
|
| 22 |
if ($args instanceof Exception) { |
| 23 |
$data .= json_encode($data->getMessage()) . "\n"; |
| 24 |
}else { |
| 25 |
$data .= json_encode($data) . "\n"; |
| 26 |
} |
| 27 |
$data .= "\n---------------------------\n\n"; |
| 28 |
|
| 29 |
$logFile = BOOKIT_LOG_PATH. $fileName . '.txt'; |
| 30 |
if ( ! is_dir( BOOKIT_LOG_PATH ) ) { |
| 31 |
wp_mkdir_p( BOOKIT_LOG_PATH ); |
| 32 |
chmod( BOOKIT_LOG_PATH, 0777 ); |
| 33 |
} |
| 34 |
|
| 35 |
file_put_contents($logFile, $data, FILE_APPEND); |
| 36 |
} |
| 37 |
|
| 38 |
} |