think\Log::write PHP Method

write() public static method

实时写入日志信息 并支持行为
public static write ( mixed $msg, string $type = 'log', boolean $force = false ) : boolean
$msg mixed 调试信息
$type string 信息类型
$force boolean 是否强制写入
return boolean
    public static function write($msg, $type = 'log', $force = false)
    {
        // 封装日志信息
        if (true === $force || empty(self::$config['level'])) {
            $log[$type][] = $msg;
        } elseif (in_array($type, self::$config['level'])) {
            $log[$type][] = $msg;
        } else {
            return false;
        }
        // 监听log_write
        Hook::listen('log_write', $log);
        if (is_null(self::$driver)) {
            self::init(Config::get('log'));
        }
        // 写入日志
        return self::$driver->save($log);
    }

Usage Example

 public function j_email()
 {
     // 如果
     if (isset($_POST['em'])) {
         $email = $_POST['em'];
         $account_model = D('Account');
         // 证明已经注册过
         if ($account_model->judge_account_id_isset($email)) {
             Response::show('-101', '该邮箱已经被注册!');
         } else {
             // 发送给用户的信息
             $rand_string = strtolower(rand_string());
             $title = '欢迎您注册!么么哒。';
             $content = '您好,您的注册验证码是 : ' . $rand_string . '   !, 如果不是本人操作,请忽略!';
             $Memcached = Memcached::getInstance();
             // 暂时不加密了。
             $Memcached->set($email, $rand_string);
             if (SendMail($email, $title, $content) === true) {
                 Response::show('200', '已经发送验证码,请注意查收!');
             } else {
                 Log::write('发送验证码失败,to [--' . $email . '--]', 'WARN');
                 Response::show('-102', '邮件发送失败,未知原因!');
             }
         }
     }
     Response::show('-103', '数据丢失!');
 }
All Usage Examples Of think\Log::write