CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 周边商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与其中
    • 问题 (Github)
    • 面包店
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • 领英
    • 优酷
    • 脸书
    • 推特
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
      • Debug
      • Middleware
      • Renderer
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 ErrorLogger

将错误和未捕获的异常记录到 Cake\Log\Log 中。

命名空间: Cake\Error

属性概要

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

    配置属性是否已使用默认值配置

  • $_defaultConfig protected
    array<string, mixed>

    默认配置值。

方法概要

  • __construct() public

    构造函数

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • alert() public

    必须立即采取行动。

  • configShallow() public

    将提供的配置与现有配置合并。与 config() 方法对嵌套键进行递归合并不同,此方法进行简单的合并。

  • critical() public

    严重状况。

  • debug() public

    详细的调试信息。

  • emergency() public

    系统不可用。

  • error() public

    运行时错误,不需要立即采取行动,但通常应记录和监控。

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • getMessage() protected

    为异常生成消息

  • getRequestContext() public

    获取错误/异常跟踪的请求上下文。

  • info() public

    有趣的事件。

  • log() public

    使用任意级别记录。

  • logError() public

    将错误记录到 Cake 的日志子系统中

  • logException() public

    记录异常的错误,并可以选择请求上下文。

  • notice() public

    正常但重要的事件。

  • setConfig() public

    设置配置。

  • warning() public

    异常情况,不是错误。

方法详情

__construct() ¶ public

__construct(array<string, mixed> $config = [])

构造函数

参数
array<string, mixed> $config optional

配置数组。

_configDelete() ¶ protected

_configDelete(string $key): void

删除单个配置键。

参数
string $key

要删除的键。

返回值
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_configRead() ¶ protected

_configRead(string|null $key): mixed

读取配置键。

参数
string|null $key

要读取的键。

返回值
mixed

_configWrite() ¶ protected

_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void

写入配置键。

参数
array<string, mixed>|string $key

要写入的键。

mixed $value

要写入的值。

string|bool $merge optional

true 表示递归合并,'shallow' 表示简单合并,false 表示覆盖,默认为 false。

返回值
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

alert() ¶ public

alert(stringStringable $message, array $context = []): void

必须立即采取行动。

示例:整个网站宕机,数据库不可用等。这应该会触发 SMS 警报并唤醒你。

参数
stringStringable $message
array $context optional
返回值
void

configShallow() ¶ public

configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this

将提供的配置与现有配置合并。与 config() 方法对嵌套键进行递归合并不同,此方法进行简单的合并。

设置特定值

$this->configShallow('key', $value);

设置嵌套值

$this->configShallow('some.nested.key', $value);

同时更新多个配置设置

$this->configShallow(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或完整的配置数组。

mixed|null $value optional

要设置的值。

返回值
$this

critical() ¶ public

critical(stringStringable $message, array $context = []): void

严重状况。

示例:应用程序组件不可用,意外异常。

参数
stringStringable $message
array $context optional
返回值
void

debug() ¶ public

debug(stringStringable $message, array $context = []): void

详细的调试信息。

参数
stringStringable $message
array $context optional
返回值
void

emergency() ¶ public

emergency(stringStringable $message, array $context = []): void

系统不可用。

参数
stringStringable $message
array $context optional
返回值
void

error() ¶ public

error(stringStringable $message, array $context = []): void

运行时错误,不需要立即采取行动,但通常应记录和监控。

参数
stringStringable $message
array $context optional
返回值
void

getConfig() ¶ public

getConfig(string|null $key = null, mixed $default = null): mixed

返回配置。

用法

读取整个配置

$this->getConfig();

读取特定值

$this->getConfig('key');

读取嵌套值

$this->getConfig('some.nested.key');

使用默认值读取

$this->getConfig('some-key', 'default-value');
参数
string|null $key optional

要获取的键,或整个配置的 null。

mixed $default optional

键不存在时的返回值。

返回值
mixed

getConfigOrFail() ¶ public

getConfigOrFail(string $key): mixed

返回此特定键的配置。

此键的配置值必须存在,不能为 null。

参数
string $key

要获取的键。

返回值
mixed
抛出
InvalidArgumentException

getMessage() ¶ protected

getMessage(Throwable $exception, bool $isPrevious = false, bool $includeTrace = false): string

为异常生成消息

参数
Throwable $exception

要为其记录消息的异常。

bool $isPrevious optional

原始异常为 false,上一个为 true

bool $includeTrace optional

是否包含堆栈跟踪。

返回值
string

getRequestContext() ¶ public

getRequestContext(Psr\Http\Message\ServerRequestInterface $request): string

获取错误/异常跟踪的请求上下文。

参数
Psr\Http\Message\ServerRequestInterface $request

要从中读取的请求。

返回值
string

info() ¶ public

info(stringStringable $message, array $context = []): void

有趣的事件。

示例:用户登录,SQL 日志。

参数
stringStringable $message
array $context optional
返回值
void

log() ¶ public

log(mixed $level, Stringable|string $message, array $context = []): void

使用任意级别记录。

参数
mixed $level
Stringable|string $message
array $context optional
返回值
void

logError() ¶ public

logError(Cake\Error\PhpError $error, Psr\Http\Message\ServerRequestInterface|null $request = null, bool $includeTrace = false): void

将错误记录到 Cake 的日志子系统中

参数
Cake\Error\PhpError $error
Psr\Http\Message\ServerRequestInterface|null $request optional
bool $includeTrace optional
返回值
void

logException() ¶ public

logException(Throwable $exception, Psr\Http\Message\ServerRequestInterface|null $request = null, bool $includeTrace = false): void

记录异常的错误,并可以选择请求上下文。

参数
Throwable $exception
Psr\Http\Message\ServerRequestInterface|null $request optional
bool $includeTrace optional
返回值
void

notice() ¶ public

notice(stringStringable $message, array $context = []): void

正常但重要的事件。

参数
stringStringable $message
array $context optional
返回值
void

setConfig() ¶ public

setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this

设置配置。

用法

设置特定值

$this->setConfig('key', $value);

设置嵌套值

$this->setConfig('some.nested.key', $value);

同时更新多个配置设置

$this->setConfig(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或完整的配置数组。

mixed|null $value optional

要设置的值。

bool $merge optional

是否递归合并或覆盖现有配置,默认为 true。

返回值
$this
抛出
Cake\Core\Exception\CakeException
尝试设置无效键时。

warning() ¶ public

warning(stringStringable $message, array $context = []): void

异常情况,不是错误。

示例:使用已弃用的 API,API 使用不当,并非错误,但并非理想。

参数
stringStringable $message
array $context optional
返回值
void

属性详情

$_config ¶ protected

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ protected

配置属性是否已使用默认值配置

类型
bool

$_defaultConfig ¶ protected

默认配置值。

  • trace 错误日志是否应包含堆栈跟踪?
类型
array<string, mixed>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与其中
  • 问题 (Github)
  • 面包店
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • 领英
  • 优酷
  • 脸书
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API Docs 生成