Skip to content

Commit e46a2eb

Browse files
committed
finnish
1 parent cd967a9 commit e46a2eb

File tree

8 files changed

+118
-10
lines changed

8 files changed

+118
-10
lines changed

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
# laravel-logsnag
33

44
[![Latest Version on Packagist](https://img.shields.io/packagist/v/expdev07/laravel-logsnag.svg?style=flat-square)](https://packagist.org/packages/expdev07/laravel-logsnag)
5-
[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/expdev07/laravel-logsnag/run-tests?label=tests)](https://github.com/expdev07/laravel-logsnag/actions?query=workflow%3Arun-tests+branch%3Amain)
6-
[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/expdev07/laravel-logsnag/Check%20&%20fix%20styling?label=code%20style)](https://github.com/expdev07/laravel-logsnag/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain)
75
[![Total Downloads](https://img.shields.io/packagist/dt/expdev07/laravel-logsnag.svg?style=flat-square)](https://packagist.org/packages/expdev07/laravel-logsnag)
86

97
Get a realtime feed of your Laravel project’s most important events using Logsnag. Supports push notifications straight to your
@@ -48,10 +46,30 @@ return [
4846
|
4947
*/
5048

49+
/**
50+
* The project name.
51+
*/
5152
'project' => env('LOGSNAG_PROJECT', 'laravel'),
5253

54+
/**
55+
* The API token.
56+
*/
5357
'token' => env('LOGSNAG_TOKEN', ''),
5458

59+
/**
60+
* A mapping of icons for logging.
61+
*/
62+
'icons' => [
63+
'DEBUG' => 'ℹ️',
64+
'INFO' => 'ℹ️',
65+
'NOTICE' => '📌',
66+
'WARNING' => '⚠️',
67+
'ERROR' => '⚠️',
68+
'CRITICAL' => '🔥',
69+
'ALERT' => '🔔️',
70+
'EMERGENCY' => '💀',
71+
],
72+
5573
];
5674
```
5775

@@ -63,8 +81,10 @@ Add the Logsnag channel to your logging config:
6381
'logsnag' => [
6482
'driver' => 'custom',
6583
'via' => ExpDev07\Logsnag\Logger\LogsnagLogger::class,
84+
'level' => 'debug',
6685
'project' => 'my-project',
6786
'channel' => 'my-channel',
87+
'notify' => true,
6888
],
6989
];
7090
```
@@ -107,6 +127,17 @@ app(LogsnagClient::class)->log(new LogsnagRequest(
107127
));
108128
```
109129

130+
## Parameters
131+
132+
* **project:** The logsnag project name.
133+
* **channel:** The channel to log in. Must be lowercase and hyphenated.
134+
* **event:** The event name.
135+
* **description:** The event description.
136+
* **icon:** Associate the log with an icon (emoji).
137+
* **notify:** Whether to send push notifications to devices.
138+
139+
See [Logsnag Log](https://sh4yy.notion.site/LogSnag-API-e942b03305c94d4fa72c8a3d24a0ad49#eb98c978cec841d0ab50d52be6eb9f80) route for more information.
140+
110141
## Testing
111142

112143
```bash

config/logsnag.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,28 @@
1111
|
1212
*/
1313

14+
/**
15+
* The project name.
16+
*/
1417
'project' => env('LOGSNAG_PROJECT', 'laravel'),
1518

19+
/**
20+
* The API token.
21+
*/
1622
'token' => env('LOGSNAG_TOKEN', ''),
1723

24+
/**
25+
* A mapping of icons for logging.
26+
*/
27+
'icons' => [
28+
'DEBUG' => 'ℹ️',
29+
'INFO' => 'ℹ️',
30+
'NOTICE' => '📌',
31+
'WARNING' => '⚠️',
32+
'ERROR' => '⚠️',
33+
'CRITICAL' => '🔥',
34+
'ALERT' => '🔔️',
35+
'EMERGENCY' => '💀',
36+
],
37+
1838
];

src/Client/LogsnagRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Contracts\Support\Arrayable;
66

7+
/**
8+
* A Logsnag logging request.
9+
*/
710
class LogsnagRequest implements Arrayable
811
{
912

src/Facades/Logsnag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @see \ExpDev07\Logsnag\Logsnag
1212
*
13-
* @method static void log(string $channel, string $event)
13+
* @method static void log(string $channel, string $event, string $description = null, string $icon = null, bool $notify = false)
1414
*/
1515
class Logsnag extends Facade
1616
{

src/Logger/LogsnagHandler.php

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
namespace ExpDev07\Logsnag\Logger;
44

55
use ExpDev07\Logsnag\Facades\Logsnag;
6+
use Illuminate\Support\Str;
67
use Monolog\Handler\AbstractProcessingHandler;
8+
use Monolog\Logger;
79

810
/**
9-
*
11+
* The Monolog processing handler.
1012
*/
1113
class LogsnagHandler extends AbstractProcessingHandler
1214
{
@@ -18,16 +20,26 @@ class LogsnagHandler extends AbstractProcessingHandler
1820
*/
1921
public string $channel;
2022

23+
/**
24+
* Whether to send push notification.
25+
*
26+
* @var string
27+
*/
28+
public string $notify;
29+
2130
/**
2231
* Constructs a new monolog Logsnag handler.
2332
*
2433
* @param string $channel
34+
* @param bool $notify
35+
* @param int $level
2536
*/
26-
public function __construct(string $channel)
37+
public function __construct(string $channel, bool $notify = false, int $level = Logger::DEBUG)
2738
{
28-
parent::__construct();
39+
parent::__construct($level);
2940

3041
$this->channel = $channel;
42+
$this->notify = $notify;
3143
}
3244

3345
/**
@@ -37,7 +49,35 @@ public function __construct(string $channel)
3749
*/
3850
protected function write(array $record): void
3951
{
40-
Logsnag::log($this->channel, $record['formatted']);
52+
Logsnag::log($this->channel,
53+
event: $this->getEvent($record),
54+
icon: $this->getIcon($record),
55+
notify: $this->notify,
56+
);
57+
}
58+
59+
/**
60+
* Gets the event for the record.
61+
*
62+
* @param array $record
63+
* @return string
64+
*/
65+
public function getEvent(array $record): string
66+
{
67+
return $record['formatted'];
68+
}
69+
70+
/**
71+
* Gets the icon for the record.
72+
*
73+
* @param array $record
74+
* @return string|null
75+
*/
76+
protected function getIcon(array $record): ?string
77+
{
78+
$icons = config('logsnag.icons');
79+
80+
return $icons[Str::upper($record['level_name'])] ?? null;
4181
}
4282

4383
}

src/Logger/LogsnagLogger.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace ExpDev07\Logsnag\Logger;
44

5-
use Arr;
5+
use Illuminate\Support\Arr;
66
use Monolog\Logger;
77

8+
/**
9+
* The Laravel Logsnag logger.
10+
*/
811
class LogsnagLogger
912
{
1013

@@ -16,9 +19,14 @@ class LogsnagLogger
1619
*/
1720
public function __invoke(array $config): Logger
1821
{
19-
[$channel] = $config;
22+
// Create handler.
23+
$handler = new LogsnagHandler(
24+
channel: $config['channel'],
25+
notify: $config['notify'] ?? false,
26+
level: Logger::toMonologLevel($config['level'] ?? 'debug'),
27+
);
2028

21-
return new Logger('logsnag', Arr::wrap(new LogsnagHandler($channel)));
29+
return new Logger('logsnag', Arr::wrap($handler));
2230
}
2331

2432
}

src/Logsnag.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use ExpDev07\Logsnag\Client\LogsnagClient;
66
use ExpDev07\Logsnag\Client\LogsnagRequest;
77

8+
/**
9+
* The Logsnag logger.
10+
*/
811
class Logsnag
912
{
1013

src/LogsnagServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Spatie\LaravelPackageTools\Package;
77
use Spatie\LaravelPackageTools\PackageServiceProvider;
88

9+
/**
10+
* The Logsnag service provider.
11+
*/
912
class LogsnagServiceProvider extends PackageServiceProvider
1013
{
1114

0 commit comments

Comments
 (0)