| 
									
										
										
										
											2019-07-24 16:51:04 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | const { SyncBailHook } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2019-07-19 18:31:18 +08:00
										 |  |  | const { Logger } = require("./Logger"); | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | const createConsoleLogger = require("./createConsoleLogger"); | 
					
						
							| 
									
										
										
										
											2019-07-19 18:31:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | /** @type {createConsoleLogger.LoggerOptions} */ | 
					
						
							| 
									
										
										
										
											2024-07-31 04:09:42 +08:00
										 |  |  | const currentDefaultLoggerOptions = { | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  | 	level: "info", | 
					
						
							| 
									
										
										
										
											2019-07-28 01:48:10 +08:00
										 |  |  | 	debug: false, | 
					
						
							|  |  |  | 	console | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | let currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions); | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {string} name name of the logger | 
					
						
							|  |  |  |  * @returns {Logger} a logger | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-07-31 11:31:11 +08:00
										 |  |  | module.exports.getLogger = name => | 
					
						
							|  |  |  | 	new Logger( | 
					
						
							| 
									
										
										
										
											2019-11-05 23:47:45 +08:00
										 |  |  | 		(type, args) => { | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | 			if (module.exports.hooks.log.call(name, type, args) === undefined) { | 
					
						
							| 
									
										
										
										
											2019-11-05 23:47:45 +08:00
										 |  |  | 				currentDefaultLogger(name, type, args); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | 		childName => module.exports.getLogger(`${name}/${childName}`) | 
					
						
							| 
									
										
										
										
											2019-11-05 23:47:45 +08:00
										 |  |  | 	); | 
					
						
							| 
									
										
										
										
											2019-07-19 18:31:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  |  * @param {createConsoleLogger.LoggerOptions} options new options, merge with old options | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  |  * @returns {void} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | module.exports.configureDefaultLogger = options => { | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  | 	Object.assign(currentDefaultLoggerOptions, options); | 
					
						
							| 
									
										
										
										
											2019-07-22 14:23:40 +08:00
										 |  |  | 	currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions); | 
					
						
							| 
									
										
										
										
											2019-07-22 04:28:46 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-31 04:54:55 +08:00
										 |  |  | module.exports.hooks = { | 
					
						
							| 
									
										
										
										
											2019-07-19 18:31:18 +08:00
										 |  |  | 	log: new SyncBailHook(["origin", "type", "args"]) | 
					
						
							|  |  |  | }; |