@@ -26,15 +26,15 @@ class Channel implements LoggerInterface
2626
2727 /**
2828 * 日志信息
29- * @var array
29+ * @var array<LogRecord>
3030 */
31- protected $ log = [];
31+ protected array $ log = [];
3232
3333 /**
3434 * 关闭日志
3535 * @var bool
3636 */
37- protected $ close = false ;
37+ protected bool $ close = false ;
3838
3939 public function __construct (protected string $ name , protected LogHandlerInterface $ logger , protected array $ allow , protected bool $ lazy , protected Event $ event )
4040 {
@@ -85,10 +85,11 @@ public function record($msg, string $type = 'info', array $context = [], bool $l
8585 $ msg = strtr ($ msg , $ replace );
8686 }
8787
88- if (!empty ($ msg ) || 0 === $ msg ) {
89- $ this ->log [] = [$ type , $ msg ];
88+ if (!empty ($ msg )) {
89+ $ record = new LogRecord ($ type , $ msg );
90+ $ this ->log [] = $ record ;
9091 if ($ this ->event ) {
91- $ this ->event ->trigger (new LogRecord ( $ type , $ msg ) );
92+ $ this ->event ->trigger ($ record );
9293 }
9394 }
9495
@@ -128,16 +129,14 @@ public function getLog(): array
128129 public function save (): bool
129130 {
130131 $ log = $ this ->log ;
131-
132- $ this ->log = [];
133-
134132 if ($ this ->event ) {
135- $ event = new LogWrite ($ this ->name , $ log );
133+ $ event = new LogWrite ($ this ->name , $ this -> log );
136134 $ this ->event ->trigger ($ event );
137135 $ log = $ event ->log ;
138136 }
139137
140138 $ this ->logger ->save ($ log );
139+ $ this ->log = [];
141140
142141 return true ;
143142 }
0 commit comments