Files
cunkebao_v3/Server/application/common/command/BaseCommand.php
2025-03-18 14:39:17 +08:00

31 lines
761 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\common\command;
use think\console\Command;
class BaseCommand extends Command {
protected $logSave = 1; // 1: 文件2: 打印
/**
* 写入日志
*
* @param $type
* @param $message
*/
public function log($type, $message) {
$data = '[' . date('Y-m-d H:i:s') . ']' . PHP_EOL;
$data .= '[' . $type . '] ' . $message . PHP_EOL . PHP_EOL;
if ($this->logSave === 1) {
$name = get_class($this);
$name = substr($name, strrpos($name, '\\') + 1);
$file = ROOT_PATH . DS . 'runtime' . DS . $name . '_' . date('Ymd') . '.txt';
file_put_contents($file, $data, FILE_APPEND);
} else {
echo $data;
}
}
}