正在设置未知属性:yii\log\Logger::targets



在我的系统中安装Yii后,当我尝试运行它时,会出现此错误。

未知属性–yii\base\UnknownPropertyException设置未知属性:yii\log\Logger::targets

以下是我在Yii中实现日志记录时创建的一些文档,可能对您有所帮助:

==========================配置examplep以从localhost代码发送电子邮件=========================

C:\examplep\php\php.ini文件的更改:

搜索[邮件功能]:

[mail function]
SMTP=localhost to SMTP=smtp.gmail.com
smtp_port=587
sendmail_from=me@example.com to sendmail_from=your email address
sendmail_path = ""C:xamppsendmailsendmail.exe" -t"
mail.add_x_header=Off
mail.log = syslog

C:\xamplep\sendmail\sendmail.ini的更改:

搜索[sendmail]:

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
debug_logfile=debug.log
auth_username=same as "sendmail_from" in php.ini file
auth_password=generated password for the email account
force_sender= same as "auth_username" in this file

========================================重新启动Xampp服务器====================================

===============================================在数据库中添加表=======================================================删除表(如果存在(";log";;

create table "log"
(
"id"          number(20) NOT NULL PRIMARY KEY,
"level"       integer,
"category"    varchar(255),
"log_time"    number,
"prefix"      text,
"message"     text,
key "idx_log_level" ("level"),
key "idx_log_category" ("category")
);

========================================Yii2项目中的配置====================================

  1. 插件";部件";app\config\console.php和app\config\web.php中的数组都是文件:

    'mailer' => [
    'class' => 'yiiswiftmailerMailer',
    // send all mails to a file by default. You have to set
    // 'useFileTransport' to false and configure a transport
    // for the mailer to send real emails.
    'useFileTransport' => false,
    'transport' => [
    'class' => 'Swift_SmtpTransport',
    'host' => 'smtp.gmail.com',
    'username' => 'your email address (for testing on localhost use same as in ini files)',
    'password' => 'generated password',
    'port' => 587,
    'encryption' => 'tls',
    ],
    ], //end of mailer
    'log' => [
    'targets' => [
    [
    'class' => 'yiilogFileTarget',
    'levels' => ['error', 'warning','info'],
    ],
    [
    'class' => 'yiilogDbTarget',
    'levels' => ['error', 'warning','info'],
    ],
    [
    'class' => 'yiilogEmailTarget',
    'mailer' => 'mailer',
    'levels' => ['error', 'warning','info'],
    //'categories' => ['yiidb*'],
    'message' => [
    'from' => ['your email address(for testing on localhost use same as in ini files)'],
    'to' => ['receiptent email address'],
    ],
    ],
    ], // end of targets
    'flushInterval' => 1,
    ], //end of logs
    

//------------------------web.php(日志配置设置(------------------------/

//类别名称稍后将被分配给消息:

Yii::info($message, 'userNotification'); 

最新更新