Skip to content

Commit c87a0bc

Browse files
authored
Merge pull request #2 from GrKamil/dev
Use config instead of env
2 parents 71b0cf7 + 320d2b0 commit c87a0bc

File tree

7 files changed

+79
-5
lines changed

7 files changed

+79
-5
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Darius Matulionis
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ Or you can simply change the default log channel in the .env
4242
LOG_CHANNEL=telegram
4343
```
4444

45+
Publish config file
46+
```
47+
php artisan vendor:publish --provider "Logger\TelegramLoggerServiceProvider"
48+
```
49+
4550
## Create bot
4651

4752
For using this package you need to create Telegram bot

composer.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
"monolog/monolog": "^1.23",
1111
"laravel/framework": "5.6.*|5.7.*"
1212
},
13-
"version":"0.1.1",
13+
"version":"0.1.2",
1414
"minimum-stability": "dev",
15-
"prefer-stable": true
15+
"prefer-stable": true,
16+
"extra": {
17+
"laravel": {
18+
"providers": [
19+
"Logger\\TelegramLoggerServiceProvider"
20+
]
21+
}
22+
}
1623
}

config/telegram-logger.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
return [
4+
// Telegram logger bot token
5+
'token' => env('TELEGRAM_LOGGER_BOT_TOKEN'),
6+
7+
// Telegram chat id
8+
'chat_id' => env('TELEGRAM_LOGGER_CHAT_ID')
9+
];

src/TelegramHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public function __construct($level)
5151
parent::__construct($level, true);
5252

5353
// define variables for making Telegram request
54-
$this->botToken = env('TELEGRAM_LOGGER_BOT_TOKEN');
55-
$this->chatId = env('TELEGRAM_LOGGER_CHAT_ID');
54+
$this->botToken = config('telegram-logger.token');
55+
$this->chatId = config('telegram-logger.chat_id');
5656

5757
// define variables for text message
5858
$this->appName = config('app.name');

src/TelegramLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TelegramLogger
1919
public function __invoke(array $config)
2020
{
2121
return new Logger(
22-
env('APP_NAME'),
22+
config('app.name'),
2323
[
2424
new TelegramHandler($config['level'])
2525
]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Logger;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
/**
8+
* Class TelegramLoggerServiceProvider
9+
* @package Logger
10+
*/
11+
class TelegramLoggerServiceProvider extends ServiceProvider
12+
{
13+
/**
14+
* Register bindings in the container.
15+
*
16+
* @return void
17+
*/
18+
public function register()
19+
{
20+
$this->mergeConfigFrom(__DIR__ . '/../config/telegram-logger.php', 'telegram-logger');
21+
}
22+
23+
/**
24+
* Perform post-registration booting of services.
25+
*
26+
* @return void
27+
*/
28+
public function boot()
29+
{
30+
$this->publishes([__DIR__ . '/../config/telegram-logger.php' => config_path('telegram-logger.php')], 'config');
31+
}
32+
}

0 commit comments

Comments
 (0)