putyourlightson / craft-log-to-file
将日志消息记录到 Craft CMS 的特定日志文件中。
2.0.0-alpha.1
2022-03-03 11:50 UTC
Requires
- craftcms/cms: ^4.0.0-alpha
README
日志到文件助手提供了一个简单的方法将消息记录到特定的文件。它旨在作为 Craft CMS 中模块和插件的辅助类使用。
Craft 4 支持
此包将不会更新以与 Craft 4 一起使用。相反,我们建议您使用自定义的 Monolog 日志目标来实现类似(更好)的结果,具体说明请参阅 https://putyourlightson.com/articles/adding-logging-to-craft-plugins-with-monolog
要求
此组件需要 Craft CMS 3.0.0 或更高版本。
使用方法
使用 composer 手动安装
composer require putyourlightson/craft-log-to-file
或将其作为插件依赖项添加
"require": {
"putyourlightson/craft-log-to-file": "^1.0.0"
},
然后您可以按照以下方式将消息写入日志文件。
use putyourlightson\logtofile\LogToFile; $message = 'The message to log.'; // Log as info LogToFile::info($message, 'my-plugin-handle'); // Log as error LogToFile::error($message, 'my-plugin-handle'); // Log as Yii message level LogToFile::log($message, 'my-plugin-handle', 'error'); // Log as custom category LogToFile::log($message, 'my-plugin-handle', 'custom-category');
结果是一个简洁的日志文件,只包含与您的模块/插件相关的消息。
文件: my-plugin-handle.log
2019-04-24 09:47:14 [info] Notification email sent to user #34.
2019-04-24 17:53:45 [info] Notification email sent to user #56.
2019-04-24 19:45:52 [error] Template `notification` not found.
2019-04-24 19:56:13 [debug] Template `notification` could not be rendered.
许可证
此软件在 MIT 许可证下免费许可。
由 PutYourLightsOn 创建。