Skip to content

Commit 5191d61

Browse files
committed
Fix: log in gitignore
1 parent 88faf19 commit 5191d61

19 files changed

+546
-0
lines changed

.github/workflows/coding-conventions.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ jobs:
2323
composer update --prefer-dist --no-interaction
2424
composer mago:install-binary
2525
26+
- name: Check Files
27+
run: |
28+
cat composer.json
29+
ls -l packages/
30+
ls -l packages/log
31+
2632
- name: Run Mago
2733
run: |
2834
./vendor/bin/mago fmt --dry-run

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ tempest.log
1717
public/static
1818
tests/Unit/Log
1919
log/
20+
!packages/log
2021
node_modules
2122
dist
2223
profile/

packages/log/.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Exclude build/test files from the release
2+
.github/ export-ignore
3+
tests/ export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
phpunit.xml export-ignore
7+
README.md export-ignore
8+
9+
# Configure diff output for .php and .phar files.
10+
*.php diff=php

packages/log/LICENCE.md

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

packages/log/composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "tempest/log",
3+
"description": "A component for logging handling.",
4+
"license": "MIT",
5+
"minimum-stability": "dev",
6+
"require": {
7+
"php": "^8.4",
8+
"monolog/monolog": "^3.7.0",
9+
"psr/log": "^3.0.0",
10+
"tempest/container": "dev-main"
11+
},
12+
"autoload": {
13+
"psr-4": {
14+
"Tempest\\Log\\": "src"
15+
}
16+
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"Tempest\\Log\\Tests\\": "tests"
20+
}
21+
}
22+
}

packages/log/phpunit.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" bootstrap="vendor/autoload.php" executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" displayDetailsOnPhpunitDeprecations="true" failOnPhpunitDeprecation="false" failOnRisky="true" failOnWarning="true">
3+
<testsuites>
4+
<testsuite name="Tempest Log">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source restrictNotices="true" restrictWarnings="true" ignoreIndirectDeprecations="true">
9+
<include>
10+
<directory>src</directory>
11+
</include>
12+
</source>
13+
</phpunit>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Log\Channels;
6+
7+
use Monolog\Handler\StreamHandler;
8+
use Monolog\Level;
9+
use Monolog\Processor\PsrLogMessageProcessor;
10+
use Tempest\Log\LogChannel;
11+
12+
final readonly class AppendLogChannel implements LogChannel
13+
{
14+
public function __construct(
15+
private string $path,
16+
private bool $bubble = true,
17+
private ?int $filePermission = null,
18+
private bool $useLocking = false,
19+
) {}
20+
21+
public function getHandlers(Level $level): array
22+
{
23+
return [
24+
new StreamHandler(
25+
stream: $this->path,
26+
level: $level,
27+
bubble: $this->bubble,
28+
filePermission: $this->filePermission,
29+
useLocking: $this->useLocking,
30+
),
31+
];
32+
}
33+
34+
public function getProcessors(): array
35+
{
36+
return [
37+
new PsrLogMessageProcessor(),
38+
];
39+
}
40+
41+
public function getPath(): string
42+
{
43+
return $this->path;
44+
}
45+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Log\Channels;
6+
7+
use Monolog\Level;
8+
use Monolog\Processor\PsrLogMessageProcessor;
9+
use Tempest\Log\FileHandlers\RotatingFileHandler;
10+
use Tempest\Log\LogChannel;
11+
12+
final readonly class DailyLogChannel implements LogChannel
13+
{
14+
public function __construct(
15+
private string $path,
16+
private int $maxFiles = 31,
17+
private bool $bubble = true,
18+
private ?int $filePermission = null,
19+
private bool $useLocking = false,
20+
) {}
21+
22+
public function getHandlers(Level $level): array
23+
{
24+
return [
25+
new RotatingFileHandler(
26+
filename: $this->path,
27+
maxFiles: $this->maxFiles,
28+
level: $level,
29+
bubble: $this->bubble,
30+
filePermission: $this->filePermission,
31+
useLocking: $this->useLocking,
32+
dateFormat: RotatingFileHandler::FILE_PER_DAY,
33+
),
34+
];
35+
}
36+
37+
public function getProcessors(): array
38+
{
39+
return [
40+
new PsrLogMessageProcessor(),
41+
];
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Log\Channels;
6+
7+
use Monolog\Level;
8+
use Monolog\Processor\PsrLogMessageProcessor;
9+
use Tempest\Log\FileHandlers\RotatingFileHandler;
10+
use Tempest\Log\LogChannel;
11+
12+
final readonly class WeeklyLogChannel implements LogChannel
13+
{
14+
public function __construct(
15+
private string $path,
16+
private int $maxFiles = 5,
17+
private bool $bubble = true,
18+
private ?int $filePermission = null,
19+
private bool $useLocking = false,
20+
) {}
21+
22+
public function getHandlers(Level $level): array
23+
{
24+
return [
25+
new RotatingFileHandler(
26+
filename: $this->path,
27+
maxFiles: $this->maxFiles,
28+
level: $level,
29+
bubble: $this->bubble,
30+
filePermission: $this->filePermission,
31+
useLocking: $this->useLocking,
32+
dateFormat: RotatingFileHandler::FILE_PER_WEEK,
33+
),
34+
];
35+
}
36+
37+
public function getProcessors(): array
38+
{
39+
return [
40+
new PsrLogMessageProcessor(),
41+
];
42+
}
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tempest\Config;
6+
7+
use Tempest\Log\LogConfig;
8+
9+
use function Tempest\env;
10+
11+
return new LogConfig(
12+
debugLogPath: env('DEBUG_LOG_PATH'),
13+
serverLogPath: env('SERVER_LOG_PATH'),
14+
);

0 commit comments

Comments
 (0)