Add ProjectZomboidBurdJournalsLog (BurdJournals.txt)
Per-line warnings emitted by the BurdJournals mod, format '[time] [BurdJournals] LEVEL: message.'. Parser captures time, the [BurdJournals] tag as the entry prefix, and the LEVEL token. Detectors: filename match plus content signature on the literal '[BurdJournals]' tag bracket.
This commit is contained in:
44
src/Log/ProjectZomboid/ProjectZomboidBurdJournalsLog.php
Normal file
44
src/Log/ProjectZomboid/ProjectZomboidBurdJournalsLog.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Log\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Analyser\AnalyserInterface;
|
||||
use IndifferentKetchup\Codex\Analyser\PatternAnalyser;
|
||||
use IndifferentKetchup\Codex\Detective\FilenameDetector;
|
||||
use IndifferentKetchup\Codex\Detective\WeightedSinglePatternDetector;
|
||||
use IndifferentKetchup\Codex\Parser\ParserInterface;
|
||||
use IndifferentKetchup\Codex\Parser\PatternParser;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\BurdJournalsPattern;
|
||||
|
||||
class ProjectZomboidBurdJournalsLog extends ProjectZomboidEventLog
|
||||
{
|
||||
public static function getDefaultParser(): ParserInterface
|
||||
{
|
||||
return static::makePatternParser(
|
||||
BurdJournalsPattern::LINE,
|
||||
[PatternParser::TIME, PatternParser::PREFIX, PatternParser::LEVEL]
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDefaultAnalyser(): AnalyserInterface
|
||||
{
|
||||
return new PatternAnalyser();
|
||||
}
|
||||
|
||||
public static function getDetectors(): array
|
||||
{
|
||||
return [
|
||||
(new FilenameDetector())
|
||||
->setPattern('/_BurdJournals\.txt$/')
|
||||
->setWeight(0.95),
|
||||
(new WeightedSinglePatternDetector())
|
||||
->setPattern('/\[BurdJournals\]/')
|
||||
->setWeight(0.95),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return "Project Zomboid BurdJournals Mod Log";
|
||||
}
|
||||
}
|
||||
18
src/Pattern/ProjectZomboid/BurdJournalsPattern.php
Normal file
18
src/Pattern/ProjectZomboid/BurdJournalsPattern.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Pattern\ProjectZomboid;
|
||||
|
||||
/**
|
||||
* Regex constants for the Project Zomboid BurdJournals.txt format.
|
||||
*
|
||||
* [time] [BurdJournals] LEVEL: message.
|
||||
*
|
||||
* LINE captures, in order:
|
||||
* 1. time
|
||||
* 2. tag (e.g. BurdJournals)
|
||||
* 3. level (WARNING | ERROR | INFO | DEBUG)
|
||||
*/
|
||||
class BurdJournalsPattern
|
||||
{
|
||||
public const string LINE = '/^\[(\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3})\] \[(\w+)\] (WARNING|ERROR|INFO|DEBUG): .+\.?$/';
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
[28-04-26 16:57:42.411] [BurdJournals] WARNING: Character ID mismatch in deleteBaseline! Client sent: local_a_b_c, Server computed: 0_a_b.
|
||||
[28-04-26 17:05:58.532] [BurdJournals] WARNING: Character ID mismatch in deleteBaseline! Client sent: local_d_e_f, Server computed: 0_d_e.
|
||||
[28-04-26 18:03:09.499] [BurdJournals] WARNING: No transferable recipes detected! authoritativeKnown=0 excludeStarting=false.
|
||||
[28-04-26 18:06:10.282] [BurdJournals] WARNING: Character ID mismatch in deleteBaseline! Client sent: local_g_h_i, Server computed: 0_g_h.
|
||||
[28-04-26 18:08:36.070] [BurdJournals] WARNING: No transferable recipes detected! authoritativeKnown=0 excludeStarting=false.
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Log;
|
||||
|
||||
use IndifferentKetchup\Codex\Detective\Detective;
|
||||
use IndifferentKetchup\Codex\Log\File\PathLogFile;
|
||||
use IndifferentKetchup\Codex\Log\Level;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidBurdJournalsLog;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ProjectZomboidBurdJournalsLogTest extends TestCase
|
||||
{
|
||||
private function fixturePath(): string
|
||||
{
|
||||
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/burd-journals-minimal.txt';
|
||||
}
|
||||
|
||||
public function testParsesEachLineAsAnEntry(): void
|
||||
{
|
||||
$log = (new ProjectZomboidBurdJournalsLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
||||
$log->parse();
|
||||
|
||||
$this->assertCount(5, $log->getEntries());
|
||||
}
|
||||
|
||||
public function testLevelAndPrefixAreParsed(): void
|
||||
{
|
||||
$log = (new ProjectZomboidBurdJournalsLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
||||
$log->parse();
|
||||
|
||||
$first = $log->getEntries()[0];
|
||||
$this->assertSame(Level::WARNING, $first->getLevel());
|
||||
$this->assertSame('BurdJournals', $first->getPrefix());
|
||||
}
|
||||
|
||||
public function testDetectiveDispatchesByContent(): void
|
||||
{
|
||||
$detective = (new Detective())
|
||||
->setLogFile(new PathLogFile($this->fixturePath()))
|
||||
->addPossibleLogClass(ProjectZomboidBurdJournalsLog::class);
|
||||
|
||||
$this->assertInstanceOf(ProjectZomboidBurdJournalsLog::class, $detective->detect());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user