@@ -61,6 +61,17 @@ public function __construct($app)
61
61
$ this ->app = $ app ;
62
62
}
63
63
64
+ /**
65
+ * Build an on-demand log channel.
66
+ *
67
+ * @param array $config
68
+ * @return \Psr\Log\LoggerInterface
69
+ */
70
+ public function build (array $ config )
71
+ {
72
+ return $ this ->get ('ondemand ' , $ config );
73
+ }
74
+
64
75
/**
65
76
* Create a new, on-demand aggregate logger instance.
66
77
*
@@ -110,12 +121,13 @@ public function getChannels()
110
121
* Attempt to get the log from the local cache.
111
122
*
112
123
* @param string $name
124
+ * @param array|null $config
113
125
* @return \Psr\Log\LoggerInterface
114
126
*/
115
- protected function get ($ name )
127
+ protected function get ($ name, ? array $ config = null )
116
128
{
117
129
try {
118
- return $ this ->channels [$ name ] ?? with ($ this ->resolve ($ name ), function ($ logger ) use ($ name ) {
130
+ return $ this ->channels [$ name ] ?? with ($ this ->resolve ($ name, $ config ), function ($ logger ) use ($ name ) {
119
131
return $ this ->channels [$ name ] = $ this ->tap ($ name , new Logger ($ logger , $ this ->app ['events ' ]));
120
132
});
121
133
} catch (Throwable $ e ) {
@@ -180,13 +192,14 @@ protected function createEmergencyLogger()
180
192
* Resolve the given log instance by name.
181
193
*
182
194
* @param string $name
195
+ * @param array|null $config
183
196
* @return \Psr\Log\LoggerInterface
184
197
*
185
198
* @throws \InvalidArgumentException
186
199
*/
187
- protected function resolve ($ name )
200
+ protected function resolve ($ name, ? array $ config = null )
188
201
{
189
- $ config = $ this ->configurationFor ($ name );
202
+ $ config = $ config ?? $ this ->configurationFor ($ name );
190
203
191
204
if (is_null ($ config )) {
192
205
throw new InvalidArgumentException ("Log [ {$ name }] is not defined. " );
@@ -242,11 +255,15 @@ protected function createStackDriver(array $config)
242
255
}
243
256
244
257
$ handlers = collect ($ config ['channels ' ])->flatMap (function ($ channel ) {
245
- return $ this ->channel ($ channel )->getHandlers ();
258
+ return $ channel instanceof LoggerInterface
259
+ ? $ channel ->getHandlers ()
260
+ : $ this ->channel ($ channel )->getHandlers ();
246
261
})->all ();
247
262
248
263
$ processors = collect ($ config ['channels ' ])->flatMap (function ($ channel ) {
249
- return $ this ->channel ($ channel )->getProcessors ();
264
+ return $ channel instanceof LoggerInterface
265
+ ? $ channel ->getProcessors ()
266
+ : $ this ->channel ($ channel )->getProcessors ();
250
267
})->all ();
251
268
252
269
if ($ config ['ignore_exceptions ' ] ?? false ) {
0 commit comments