Skip to content

Commit 52f200a

Browse files
kevinfrombrendt
andauthored
feat(log): configure log paths through env by default (#820)
Co-authored-by: Brent Roose <[email protected]>
1 parent 94f343e commit 52f200a

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ CONFIG_CACHE=false
1818
VIEW_CACHE=false
1919

2020
# Enable or disable project cache (allround cache)
21-
PROJECT_CACHE=false
21+
PROJECT_CACHE=false
22+
23+
# Overwrite default log paths (null = default)
24+
DEBUG_LOG_PATH=null
25+
SERVER_LOG_PATH=null

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ debug.log
1313
tempest.log
1414
public/static
1515
tests/Unit/Log
16+
log/

phpunit.xml.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<env name="BASE_URI" value="" />
3434
<env name="CACHE" value="null" />
3535
<env name="DISCOVERY_CACHE" value="true" />
36+
<env name="DEBUG_LOG_PATH" value="log/debug.test.log" />
37+
<env name="SERVER_LOG_PATH" value="log/server.test.log" />
3638
<ini name="memory_limit" value="256M" />
3739
</php>
3840
</phpunit>

src/Tempest/Log/src/Config/logs.config.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
namespace Tempest\Config;
66

77
use Tempest\Log\LogConfig;
8+
use function Tempest\env;
89

9-
return new LogConfig();
10+
return new LogConfig(
11+
debugLogPath: env('DEBUG_LOG_PATH'),
12+
serverLogPath: env('SERVER_LOG_PATH'),
13+
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Log;
6+
7+
use Tempest\Log\LogConfig;
8+
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
9+
10+
/**
11+
* @internal
12+
*/
13+
final class LogConfigTest extends FrameworkIntegrationTestCase
14+
{
15+
public function test_log_path_by_env(): void
16+
{
17+
$expectedDebugLogPath = 'log/debug.test.log';
18+
$expectedServerLogPath = 'log/server.test.log';
19+
20+
$this->kernel->loadConfig();
21+
22+
$logConfig = $this->container->get(LogConfig::class);
23+
24+
$this->assertSame($expectedDebugLogPath, $logConfig->debugLogPath);
25+
$this->assertSame($expectedServerLogPath, $logConfig->serverLogPath);
26+
}
27+
}

0 commit comments

Comments
 (0)