tenweb-speed-optimizer
/
vendor
/
10web-utils
/
tenweb-image-optimizer
/
src
/
TenWebIO
Last commit date
Exceptions
4 years ago
Queue
2 years ago
Views
2 years ago
Api.php
2 years ago
Attachments.php
2 years ago
Backup.php
2 years ago
CLI.php
3 years ago
Compress.php
2 years ago
CompressDataService.php
3 years ago
CompressService.php
3 years ago
Config.php
2 years ago
Init.php
2 years ago
LastCompress.php
3 years ago
Logs.php
2 years ago
PreInit.php
3 years ago
Rest.php
2 years ago
Settings.php
3 years ago
Utils.php
1 year ago
Logs.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | namespace TenWebIO; |
| 4 | |
| 5 | class Logs |
| 6 | { |
| 7 | /** |
| 8 | * @param $key |
| 9 | * @param $msg |
| 10 | * @param string $type // log, error |
| 11 | * |
| 12 | * @return void |
| 13 | */ |
| 14 | public static function setLog($key, $msg, $type = 'log') |
| 15 | { |
| 16 | $config = new Config(); |
| 17 | if (empty($config->getDebugMode()) && $type != 'error') { |
| 18 | return; |
| 19 | } |
| 20 | $logs = self::getLogs(); |
| 21 | |
| 22 | // add log to the beginning of existing logs |
| 23 | if (!(is_string($msg) || is_numeric($msg))) { |
| 24 | $msg = json_encode($msg); |
| 25 | } |
| 26 | if (count($logs) >= 50) { |
| 27 | Logs::clearLogs(); |
| 28 | } |
| 29 | $logs[$key] = array('msg' => $msg, 'date' => date('Y-m-d H:i:s'), 'type' => $type); |
| 30 | $expiration = 6 * 60 * 60; |
| 31 | set_transient(TENWEBIO_PREFIX . '_logs', $logs, $expiration); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @return array |
| 36 | */ |
| 37 | public static function getLogs() |
| 38 | { |
| 39 | $logs = get_transient(TENWEBIO_PREFIX . '_logs'); |
| 40 | if (!is_array($logs)) { |
| 41 | $logs = array(); |
| 42 | } |
| 43 | |
| 44 | return $logs; |
| 45 | } |
| 46 | |
| 47 | public static function clearLogs() |
| 48 | { |
| 49 | delete_transient(TENWEBIO_PREFIX . '_logs'); |
| 50 | } |
| 51 | } |
| 52 |