fresh/src/State/Log.php
Christopher Vagnetoft ec1659e96d Refactoring and cleanup
* Moved logic from entrypoint to a dedicated class.
* Disabled automatic flush of state.
* Added locking support to prevent multiple instances.
* Added logging
* Added base interface for CredentialsLoader
2022-03-09 01:09:28 +01:00

39 lines
725 B
PHP

<?php
namespace NoccyLabs\FreshDocker\State;
class Log
{
private bool $verbose = false;
private array $log = [];
public function __construct(bool $verbose=false)
{
$this->verbose = $verbose;
}
public function setVerbose(bool $verbose)
{
$this->verbose = $verbose;
}
public function append(string $message)
{
array_push($this->log, $message);
if ($this->verbose) {
fwrite(STDOUT, $message . "\n");
}
}
public function flush()
{
if ($this->verbose) return;
fwrite(STDOUT, join("\n", $this->log)."\n");
}
public function asString(): string
{
return join("\n", $this->log);
}
}