deniscosmin21/log-service-php

关于该包的最新版本(v1.2.7)没有可用的许可证信息。

v1.2.7 2024-09-10 10:23 UTC

README

安装

composer require deniscosmin21/log-service-php

自定义:为了添加自定义选项,您应在.env文件中添加

API_PASS_KEY=your_api_key
API_PASS_VALUE=your_api_value
ERROR_NAME=custom_path_to_error_log_file #basic is error.log
INFO_NAME=custom_path_to_info_log_file #basic is info.log
WARNING_NAME=custom_path_to_warning_log_file #basic is warning.log
SUCCESS_NAME=custom_path_to_success_log_file #basic is info.log
CUSTOM_PATH=custom_folder_for_logs #basic is /log_records
SOURCE=the_source_of_log

使用方法

如果您有一个没有laravel的php项目,您必须使用

require '../vendor/autoload.php';

来使用composer包中的命名空间

初始化

use Deniscosmin21\LogServicePhp\LogData;

指定源

use Deniscosmin21\LogServicePhp\LogData;

$logger = new LogData();

LogData::source('source');

如果您已在.env文件中指定了源,则此操作不是必需的

指定日志类型

您可以使用类似于laravel的自定义方法

use Deniscosmin21\LogServicePhp\LogData;

LogData::info() #for informational log

LogData::error() #for error log

LogData::warning() #for warning log

LogData::success() #for success log

您甚至可以在内部指定日志的消息

LogData::info('my custom message');

或者您可以使用

LogData::details('the_type_of_log_you_want', 'your_log_message');

第一个参数是类型,第二个参数是详情。对于发送日志通知,您可以使用带字符串参数的电子邮件方法,例如

"test@test.com,test2@test.com" "test@test.com"

LogData::email('your_email_string_list_here');

或者您可以发送电子邮件数组,例如

LogData::email($your_email_array_list_here);

数组应如下所示:[(0) => 'first_email', (1) => 'second_email'] 使用电子邮件方法,您可以指定任意数量的电子邮件

对于发送短信通知,您可以使用

LogData::sms('07....');

但请注意,此方法将日志发送到短信和电子邮件,因此使用方式应如下

LogData::email('emails')->sms('07....');

要使用API凭证,您可以使用每个值的字符串

LogData::credentials('credentials_key', 'credentials_value');

或者您可以使用包含以下内容的数组:['key' => 'credentials_key', 'value' => 'credentials_value']

LogData::credentials(['key' => 'credentials_key', 'value' => 'credentials_value']);

如果您已在.env文件中指定了凭证,则无需指定凭证

设置所有信息后发送日志,只需使用

LogData::send(); #This gets the response of the request too
LogData::chained_metods() #no need for using send

完整使用示例

use Deniscosmin21\LogServicePhp\LogData;

return LogData::info('my_info_log')->source('source')->email('test@gmail.com')->credentials('key', 'value');

或者如果.env文件已全部设置

use Deniscosmin21\LogServicePhp\LogData;

return LogData::info('my_info_log')->email('test@gmail.com');

更多信息:在请求错误的情况下,记录器将返回包含指定消息及其错误的响应。如果发生任何错误,日志将注册在.env文件中指定的路径或基本路径上,日志内容为:"[log_type log, in date : date_time_of_log] : Detalii : details; Locatie : location of the log."

.env文件应存储在目录的根目录中,否则应用程序将失败