roublez/logsnag-php

LogSnag API 的 PHP SDK

2.0.0 2024-03-07 20:14 UTC

This package is not auto-updated.

Last update: 2024-09-26 05:36:51 UTC


README

LogSnag PHP

LogSnag API 的 PHP SDK – logsnag.com

安装

composer require hallewood/logsnag-php

用法

初始化客户端

use Hallewood\LogSnag\Client;

$logsnag = new Client('7f568d735724351757637b1dbf108e5', 'my-project');

项目名称将在所有请求中自动注入。

日志

//
// The channel and the event name are the only required parameters.
$logsnag->log('subscriptions', 'User subscribed!');

//
// Other parameters can be added when needed.
$logsnag->log(
    channel: 'subscriptions',
    event: 'User subscribed!',
    userId: '123-456',
    description: 'A new user subscribed to the **premium plan**.',
    icon: '👍🏼',
    notify: true,
    tags: [
        'payment-method': 'card',
        'plan': 'monthly',
    ],
    parser: 'markdown',
    timestamp: 1709842921,
);

标识

//
// Both the user id and the properties are required.
$logsnag->identify(
    userId: '123-456',
    properties: [
        'active': 'yes',
        'signed-in': 'no',
    ],
);

洞察

//
// The title and the value are the only required parameters.
$logsnag->insight('Subscribed Users', 12);

//
// Other parameters can be added when needed.
$logsnag->log(
    title: 'Status',
    value: 'watered',
    icon: '🪴',
);

洞察变更

//
// The title and at least one mutation is required.
$logsnag->insight('Subscribed Users', inc: 3);

//
// Other parameters can be added when needed.
$logsnag->log(
    title: 'Subscribed Users',
    inc: -2,
    icon: '👍🏼',
);