Skip to content

Commit

Permalink
Small fixes and renamed ProcessIDChannel class to the `DifferentLog…
Browse files Browse the repository at this point in the history
…sChannel`
  • Loading branch information
Andrey Helldar committed Jun 22, 2020
1 parent a34f4ce commit 8f89457
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ Add a new channel in file `config/logging.php` or modify an existing one using o

1.
```php
use Helldar\LaravelLoggerChannels\Loggers\ProcessesRotation\ProcessIDChannel;
use Helldar\LaravelLoggerChannels\Loggers\ProcessesRotation\DifferentLogsChannel;

return [
'channels' => [
'your_channel' => ProcessIDChannel::get(
'your_channel' => DifferentLogsChannel::get(
storage_path('logs/your-filename.log')
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Helldar\LaravelLoggerChannels\Loggers\ProcessesRotation;

class ProcessIDChannel
class DifferentLogsChannel
{
public static function get(string $path, int $days = 14): array
{
Expand Down
28 changes: 24 additions & 4 deletions src/Loggers/ProcessesRotation/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use DateTime;
use DateTimeInterface;
use Helldar\LaravelLoggerChannels\Traits\LogConfiguration;
use Helldar\LaravelLoggerChannels\Traits\Configurable;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger as Monolog;

class Logger
{
use LogConfiguration;
use Configurable;

public function __invoke(array $config)
{
Expand Down Expand Up @@ -58,8 +58,28 @@ protected function date(): DateTimeInterface
return new DateTime();
}

protected function getFallbackChannelName()
protected function getConfigPath(array $config): ?string
{
return 'production';
return $config['path'] ?? null;
}

protected function getConfigDays(array $config): int
{
return $config['days'] ?? 7;
}

protected function getConfigBubble(array $config): bool
{
return (bool) ($config['bubble'] ?? true);
}

protected function getConfigPermission(array $config): ?int
{
return $config['permission'] ?? null;
}

protected function getConfigLocking(array $config): bool
{
return (bool) ($config['locking'] ?? false);
}
}
32 changes: 5 additions & 27 deletions src/Traits/LogConfiguration.php → src/Traits/Configurable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use InvalidArgumentException;
use Monolog\Logger as Monolog;

trait LogConfiguration
trait Configurable
{
/**
* The Log levels.
Expand All @@ -28,7 +28,10 @@ trait LogConfiguration
*
* @return string
*/
abstract protected function getFallbackChannelName();
protected function getFallbackChannelName()
{
return 'production';
}

/**
* Parse the string level into a Monolog constant.
Expand Down Expand Up @@ -61,29 +64,4 @@ protected function channelName(array $config)
{
return $config['name'] ?? $this->getFallbackChannelName();
}

protected function getConfigPath(array $config): ?string
{
return $config['path'] ?? null;
}

protected function getConfigDays(array $config): int
{
return $config['days'] ?? 7;
}

protected function getConfigBubble(array $config): bool
{
return (bool) ($config['bubble'] ?? true);
}

protected function getConfigPermission(array $config): ?int
{
return $config['permission'] ?? null;
}

protected function getConfigLocking(array $config): bool
{
return (bool) ($config['locking'] ?? false);
}
}

0 comments on commit 8f89457

Please sign in to comment.