Skip to content

Commit d31b4a9

Browse files
authored
Merge pull request #48 from danielme85/dev
Updates
2 parents 11fc22f + ad05319 commit d31b4a9

File tree

9 files changed

+56
-31
lines changed

9 files changed

+56
-31
lines changed

.github/workflows/docker.yml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
name: TestInDocker
1+
name: RunPhpUnitInDocker
22

33
on:
44
push:
55
branches:
66
- main
7+
- dev
78
pull_request:
89
branches:
910
- main
1011

1112
jobs:
12-
run-test-image:
13-
runs-on: ubuntu:latest
14-
timeout-minutes: 5
15-
container: ghcr.io/danielme85/lltdb-testbench:latest
13+
docker:
14+
timeout-minutes: 15
15+
runs-on: ubuntu-latest
1616

1717
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v1
20+
1821
- name: Start containers
1922
run: docker-compose up -d mariadb mongo
2023

21-
- name: Install composer packages
22-
run: cd /var/testing && composer install --no-interaction
23-
24-
- name: Run tests
25-
run: cd /var/testing && dockerize -wait tcp://mariadb:3306 -timeout 1m && ./vendor/bin/testbench package:test
26-
27-
- name: Upload test coverage
28-
uses: codecov/codecov-action@v3
29-
with:
30-
files: ./clover.xml
24+
- name: Start test container
25+
run: docker-compose up php8
3126

3227
- name: Cleanup containers
3328
run: docker-compose down
34-

docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: "2.4"
33
services:
44

55
mariadb:
6-
image: mariadb:10.5
6+
image: mariadb:latest
77
container_name: laravel-log-to-db-mariadb
88
networks:
99
- laravel-log-to-db-testing
@@ -24,6 +24,7 @@ services:
2424
php8:
2525
image: ghcr.io/danielme85/lltdb-testbench
2626
container_name: laravel-log-to-db-php8
27+
tty: true
2728
build:
2829
context: ./docker/php8/
2930
dockerfile: Dockerfile

phpunit.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<exclude>
1111
<directory>./vendor</directory>
1212
</exclude>
13-
<report>
14-
<clover outputFile="./clover.xml"/>
15-
</report>
1613
</coverage>
1714
<testsuites>
1815
<testsuite name="Test Suite danielme85/laravel-log-to-db">

readme.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,19 @@ LogToDB::model()->removeOlderThan('2019-01-01 23:00:00');
324324

325325
## Processors
326326
Monolog ships with a set of [processors](https://github.com/Seldaek/monolog/tree/master/src/Monolog/Processor), these will generate additional data and populate the 'extra' field.
327+
I've also added a couple of example processors in this pacage under src/Processors.
328+
To enable processors you can add them to the log config array:
329+
```php
330+
'database' => [
331+
'driver' => 'custom',
332+
'via' => danielme85\LaravelLogToDB\LogToDbHandler::class
333+
...
334+
'processors' => [
335+
\danielme85\LaravelLogToDB\Processors\PhpVersionProcessor::class,
336+
Monolog\Processor\HostnameProcessor::class,
337+
]
338+
339+
```
327340

328341
You could also create your own custom processor, make sure they implement [Monolog\Processor\ProcessorInterface](https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/ProcessorInterface.php).
329342

@@ -415,6 +428,8 @@ You also need to make sure that all the needed basic config values for logtodb i
415428
* or just add all your log-to-db options in your applications config/logging.php file (probably easiest). Just follow the
416429
configuration example above under the [configuration](#configuration) section.
417430

431+
Since we are using Lumen we need to specify the config and service providers in the "bootstrap/app.php" file.
432+
418433
```
419434
/*
420435
|--------------------------------------------------------------------------
@@ -452,9 +467,9 @@ Next step is to register the service provider, either in bootstrap/app.php or in
452467
$app->register(\danielme85\LaravelLogToDB\ServiceProvider::class);
453468
```
454469

455-
After adding the service provider you should be able to run the database migration with:
470+
After adding the service provider you should be able to run the database migration in Lumen with:
456471
```
457-
php artisan migrate
472+
php artisan migrate --path=vendor/danielme85/laravel-log-to-db/src/migrations/2018_08_11_003343_create_log_table.php
458473
```
459474
Please note that you need a working db connection in Lumen at this point.
460475

src/Facades/LogToDB.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace danielme85\LaravelLogToDB\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class LogToDB extends Facade
8+
{
9+
/**
10+
* @return string
11+
*/
12+
protected static function getFacadeAccessor()
13+
{
14+
return 'laravel-log-to-db';
15+
}
16+
17+
}

src/LogToDB.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function newFromMonolog(array $record)
150150
} else if (!$detailed) {
151151
$record['context'] = null;
152152
}
153-
if ($this->config['queue']) {
153+
if (!empty($this->config['queue'])) {
154154
if (empty($this->config['queue_name']) && empty($this->config['queue_connection'])) {
155155
dispatch(new SaveNewLogEvent($this, $record));
156156
} else if (!empty($this->config['queue_name']) && !empty($this->config['queue_connection'])) {

src/LogToDbCustomLoggingHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class LogToDbCustomLoggingHandler extends AbstractProcessingHandler
2525
/**
2626
* LogToDbHandler constructor.
2727
*
28-
* @param array $config Logging configuration from logging.php8
28+
* @param array $config Logging configuration from logging.php
2929
* @param array $processors collection of log processors
3030
* @param bool $bubble Whether the messages that are handled can bubble up the stack or not
3131
*/

src/ServiceProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function boot()
2727
{
2828
//config path is missing in Lumen
2929
//https://gist.github.com/mabasic/21d13eab12462e596120
30-
if (!function_exists('config_path')) {
30+
if (!function_exists('config_path') &&
31+
!function_exists('danielme85\LaravelLogToDB\config_path')) {
3132
function config_path($path = '')
3233
{
3334
return app()->basePath() . '/config' . ($path ? '/' . $path : $path);
@@ -37,7 +38,7 @@ function config_path($path = '')
3738
//Merge config first, then keep a publish option
3839
$this->mergeConfigFrom(__DIR__.'/config/logtodb.php', 'logtodb');
3940
$this->publishes([
40-
__DIR__.'/config/logtodb.php' => config_path('logtodb.php8'),
41+
__DIR__.'/config/logtodb.php' => config_path('logtodb.php'),
4142
], 'config');
4243

4344
//Publish the migration

src/config/logtodb.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
|--------------------------------------------------------------------------
66
|
77
| These settings are ONLY USED if they are not specified per channel
8-
| in the config/logging.php8 file.
8+
| in the config/logging.php file.
99
|
1010
*/
1111
return [
@@ -15,11 +15,11 @@
1515
|--------------------------------------------------------------------------
1616
|
1717
| Set the default database connection to use. This is only used if no connection
18-
| is specified in config/logging.php8. Matches connections in the config/database.php8.
18+
| is specified in config/logging.php. Matches connections in the config/database.php.
1919
| The default is: 'default', this will use whatever is default in the Laravel DB
2020
| config file. To use a different or separate connection set the connection name here.
21-
| Ex: 'connection' => 'mysql' wil use the connection 'mysql' in database.php8.
22-
| Ex: 'connection' => 'mongodb' wil use the connection 'mongodb' in database.php8*
21+
| Ex: 'connection' => 'mysql' wil use the connection 'mysql' in database.php.
22+
| Ex: 'connection' => 'mongodb' wil use the connection 'mongodb' in database.php*
2323
|
2424
| Supported connections should be same as Laravel since the Laravel DB/Eloquent
2525
| Supported DB engines as of this writing: [MySQL] [PostgreSQL] [SQLite] [SQL Server]
@@ -89,7 +89,7 @@
8989
|
9090
| If you are working with multiple queue connections, you may specify which
9191
| connection to push a job to.
92-
| This relates yto your queue settings in the config/queue.php8 file.
92+
| This relates yto your queue settings in the config/queue.php file.
9393
| Leave blank to use the default connection.
9494
|
9595
*/

0 commit comments

Comments
 (0)