-
Notifications
You must be signed in to change notification settings - Fork 5
/
Log.php
98 lines (86 loc) · 2.46 KB
/
Log.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Copyright (c) 2018. Codex Project.
*
* The license can be found in the package and online at https://codex-project.mit-license.org.
*
* @copyright 2018 Codex Project
* @author Robin Radic
* @license https://codex-project.mit-license.org MIT License
*/
namespace Codex\Log;
use Codex\Contracts\Log\Log as LogContract;
use Illuminate\Console\Command;
use Monolog\Formatter\ChromePHPFormatter;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\ChromePHPHandler;
use Monolog\Handler\FirePHPHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger as BaseLogger;
/**
* This is the class Logger.
*
* @author Codex Project
* @copyright Copyright (c) 2015, Codex Project. All rights reserved
*/
class Log extends BaseLogger implements LogContract
{
protected $enabled;
public function __construct()
{
parent::__construct('codex');
$this->enabled = true;
}
public function useFiles($path, $level = self::DEBUG)
{
$formatter = tap(new LineFormatter(null, null, true, true), function ($formatter) {
$formatter->includeStacktraces();
});
$handler = new StreamHandler($path, $level);
$this->pushHandler($handler->setFormatter($formatter));
return $handler;
}
/**
* Register a file log handler.
*
* @param string $path
* @param string $level
*/
public function useChromePHP($level = self::DEBUG)
{
$this->pushHandler($handler = new ChromePHPHandler($level));
$handler->setFormatter($formatter = new ChromePHPFormatter());
return $handler;
}
public function useFirePHP($level = self::DEBUG)
{
$this->pushHandler($handler = new FirePHPHandler($level));
return $handler;
}
protected $artisanHandler;
public function useArtisan(Command $command, $level = self::DEBUG)
{
if ($this->artisanHandler === null) {
$this->pushHandler($this->artisanHandler = new ArtisanHandler($command, $level));
}
return $this->artisanHandler;
}
/**
* Set the enabled value.
*
* @param mixed $enabled
*
* @return Log
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
return $this;
}
public function addRecord($level, $message, array $context = [])
{
if ($this->enabled) {
parent::addRecord($level, $message, $context);
}
}
}