@@ -110,12 +110,13 @@ public function getChannels()
110
110
* Attempt to get the log from the local cache.
111
111
*
112
112
* @param string $name
113
+ * @param array|null $config
113
114
* @return \Psr\Log\LoggerInterface
114
115
*/
115
- protected function get ($ name )
116
+ protected function get ($ name, ? array $ config = null )
116
117
{
117
118
try {
118
- return $ this ->channels [$ name ] ?? with ($ this ->resolve ($ name ), function ($ logger ) use ($ name ) {
119
+ return $ this ->channels [$ name ] ?? with ($ this ->resolve ($ name, $ config ), function ($ logger ) use ($ name ) {
119
120
return $ this ->channels [$ name ] = $ this ->tap ($ name , new Logger ($ logger , $ this ->app ['events ' ]));
120
121
});
121
122
} catch (Throwable $ e ) {
@@ -180,13 +181,14 @@ protected function createEmergencyLogger()
180
181
* Resolve the given log instance by name.
181
182
*
182
183
* @param string $name
184
+ * @param array|null $config
183
185
* @return \Psr\Log\LoggerInterface
184
186
*
185
187
* @throws \InvalidArgumentException
186
188
*/
187
- protected function resolve ($ name )
189
+ protected function resolve ($ name, ? array $ config = null )
188
190
{
189
- $ config = $ this ->configurationFor ($ name );
191
+ $ config = $ config ?? $ this ->configurationFor ($ name );
190
192
191
193
if (is_null ($ config )) {
192
194
throw new InvalidArgumentException ("Log [ {$ name }] is not defined. " );
@@ -242,11 +244,15 @@ protected function createStackDriver(array $config)
242
244
}
243
245
244
246
$ handlers = collect ($ config ['channels ' ])->flatMap (function ($ channel ) {
245
- return $ this ->channel ($ channel )->getHandlers ();
247
+ return $ channel instanceof LoggerInterface
248
+ ? $ channel ->getHandlers ()
249
+ : $ this ->channel ($ channel )->getHandlers ();
246
250
})->all ();
247
251
248
252
$ processors = collect ($ config ['channels ' ])->flatMap (function ($ channel ) {
249
- return $ this ->channel ($ channel )->getProcessors ();
253
+ return $ channel instanceof LoggerInterface
254
+ ? $ channel ->getProcessors ()
255
+ : $ this ->channel ($ channel )->getProcessors ();
250
256
})->all ();
251
257
252
258
if ($ config ['ignore_exceptions ' ] ?? false ) {
@@ -630,6 +636,17 @@ public function log($level, $message, array $context = [])
630
636
$ this ->driver ()->log ($ level , $ message , $ context );
631
637
}
632
638
639
+ /**
640
+ * Build an on-demand channel.
641
+ *
642
+ * @param array $config
643
+ * @return \Psr\Log\LoggerInterface
644
+ */
645
+ public function build (array $ config )
646
+ {
647
+ return $ this ->get ('ondemand ' , $ config );
648
+ }
649
+
633
650
/**
634
651
* Dynamically call the default driver instance.
635
652
*
0 commit comments