Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit abff530

Browse files
committed
feat: Delete Log with Cron and Refacto Logging Config
Delete log with a cron that trigger at midnight. Also refactored logging config so that the developer does not have to do anything with copy/pasting the config, only setting ENV values will be good. Closes #13
1 parent c792d69 commit abff530

17 files changed

+466
-132
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
vendor
22
composer.lock
33
.phpunit.result.cache
4+
.idea
5+
coverage/*

.idea/.gitignore

Lines changed: 0 additions & 48 deletions
This file was deleted.

README.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,33 @@ I would highly suggest you to use the DataDog Agent Style rather than the Api St
2222

2323
1) Firstly, install the agent by <a href="https://app.datadoghq.com/account/settings#agent">following this guide here</a>
2424

25-
2) Add in your `config/logging.php` the following under `channels` tab:
26-
27-
'datadog-agent' => [
28-
'driver' => 'custom',
29-
'via' => CreateDataDogAgentLogger::class,
30-
'path' => storage_path('logs/laravel-json-datadog.log'),
31-
'level' => 'info', // choose your minimum level of logging.
32-
'permission' => 0664,
33-
'bubble' => true,
34-
],
25+
1) Please fill in your .env the following values:
26+
27+
DATADOG_STORAGE_PATH="logs/laravel-json-datadog.log"
28+
DATADOG_PERMISSIONS=0644 // Default to 0644 if no value provided
29+
DATADOG_LEVEL="info" // Default to info if no value provided
30+
DATADOG_BUBBLE=true // Default to true if no value provided
31+
3532
3) Add `LOG_CHANNEL="datadog-agent"` in your `.env` file OR include `datadog-agent` channel into your stack log channel.
3633
4) Enable logs by setting `logs_enabled: true` in the default `/etc/datadog-agent/datadog.yaml` file on the server where the project is hosted.
3734
5) Choose only one config between those 3 files to put in `/etc/datadog-agent/conf.d/laravel.d/` (create the `laravel.d` folder if it doesn't exist) :
38-
1) <a href="https://github.com/myLocalInfluence/laravel-datadog-logger/blob/master/conf/cli-only/conf.yaml">Logging only php-cli</a>
39-
2) <a href="https://github.com/myLocalInfluence/laravel-datadog-logger/blob/master/conf/fpm-only/conf.yaml">Logging only php-fpm</a>
40-
3) <a href="https://github.com/myLocalInfluence/laravel-datadog-logger/blob/master/conf/cli-fpm/conf.yaml">Logging php-fpm and php-cli</a>
35+
1) <a href="https://github.com/myLocalInfluence/laravel-datadog-logger/blob/master/config/agent/cli-only/conf.yaml">Logging only php-cli</a>
36+
2) <a href="https://github.com/myLocalInfluence/laravel-datadog-logger/blob/master/config/agent/fpm-only/conf.yaml">Logging only php-fpm</a>
37+
3) <a href="https://github.com/myLocalInfluence/laravel-datadog-logger/blob/master/config/agent/cli-fpm/conf.yaml">Logging php-fpm and php-cli</a>
4138
6) Restart your DataDog Agent and watch your result <a href="https://app.datadoghq.com/logs/livetail">here</a>.
4239

4340
Notes: At this time the `source` metadata from the DataDogFormatter is not taken care by DataDog so that's why we are specifying it in the `/etc/datadog-agent/conf.d/laravel.d/conf.yaml` file.
4441

4542
## 2) How to use in API Style
4643

47-
1) Add in your `config/logging.php` the following under `channels` tab:
44+
1) Please fill in your .env the following values (<a href="https://app.datadoghq.com/account/settings#api">How to obtain ApiKey ?</a>) :
4845

49-
'datadog-api' => [
50-
'driver' => 'custom',
51-
'via' => \Myli\CreateDataDogLogger::class,
52-
'apiKey' => env('DATADOG_API_KEY'),
53-
'region' => 'eu', // eu or us
54-
'level' => 'info', // choose your minimum level of logging.
55-
'bubble' => true,
56-
],
46+
`DATADOG_API_KEY="YOUR_API_KEY"
47+
DATADOG_REGION="eu|us" // Default to eu if no value provided
48+
DATADOG_LEVEL="info" // Default to info if no value provided
49+
DATADOG_BUBBLE=true // Default to true if no value provided`
5750

5851
2) And finally add `LOG_CHANNEL="datadog-api"` in your `.env` file OR include `datadog-api` channel into your stack log channel.
59-
3) The only custom options are `region` (values can be `us|eu`) and `apiKey` which you can find <a href="https://app.datadoghq.com/account/settings#api">here</a>
6052

6153
## If you ❤️ open-source software, give the repos you use a ⭐️.
6254
We have included the awesome `symfony/thanks` composer package as a dev

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
"symfony/thanks": "*",
3838
"php-mock/php-mock-phpunit": "^2.4"
3939
},
40+
"extra": {
41+
"laravel": {
42+
"providers": [
43+
"Myli\\DatadogLogger\\Providers\\DataDogServiceProvider"
44+
]
45+
}
46+
},
4047
"autoload": {
4148
"psr-4": {
4249
"Myli\\DatadogLogger\\": "src/"
File renamed without changes.
File renamed without changes.
File renamed without changes.

config/logging.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Myli\DatadogLogger\Agent\CreateDataDogAgentLogger;
4+
use Myli\DatadogLogger\Api\CreateDataDogApiLogger;
5+
6+
return [
7+
'datadog-agent' => [
8+
'driver' => 'custom',
9+
'via' => CreateDataDogAgentLogger::class,
10+
'path' => storage_path(env('DATADOG_STORAGE_PATH')),
11+
'level' => env('DATADOG_LEVEL', 'info'), // choose your minimum level of logging.
12+
'permission' => env('DATADOG_PERMISSIONS', 0644),
13+
'bubble' => env('DATADOG_BUBBLE', true),
14+
],
15+
'datadog-api' => [
16+
'driver' => 'custom',
17+
'via' => CreateDataDogApiLogger::class,
18+
'apiKey' => env('DATADOG_API_KEY'),
19+
'region' => env('DATADOG_REGION', 'eu'), // eu or us
20+
'level' => env('DATADOG_LEVEL', 'info'), // choose your minimum level of logging.
21+
'bubble' => env('DATADOG_BUBBLE', true),
22+
],
23+
];

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
convertErrorsToExceptions="true"
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
9-
processIsolation="false"
9+
processIsolation="true"
1010
stopOnFailure="false">
1111
<testsuites>
1212
<testsuite name="Unit">

src/Agent/CreateDataDogAgentLogger.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,16 @@ class CreateDataDogAgentLogger
2626
*/
2727
public function __invoke(array $config)
2828
{
29-
if (empty($config['path'])) {
29+
if ($config['path'] === storage_path()) {
3030
$config['path'] = storage_path('logs/laravel-json-datadog.log');
3131
}
3232

33-
if (\is_string($config['path'])) {
34-
$pathInfo = pathinfo($config['path']);
35-
$config['path'] = str_replace(
36-
$pathInfo['filename'],
37-
$pathInfo['filename'] . '-' . php_sapi_name(),
38-
$config['path']
39-
);
40-
}
33+
$pathInfo = pathinfo($config['path']);
34+
$config['path'] = str_replace(
35+
$pathInfo['filename'],
36+
$pathInfo['filename'] . '-' . php_sapi_name(),
37+
$config['path']
38+
);
4139

4240
$streamHandler = new StreamHandler(
4341
$config['path'],

0 commit comments

Comments
 (0)