* Determines if a provided logger object meets the requirements * of a Fastify compatible logger. * * @param {object} logger Object to validate. * @param {boolean?} strict `true` if the object must be a logger (always throw if any methods missing) * * @returns {boolean} `true` when the logger
(logger, strict)
| 58 | * missing required methods. |
| 59 | */ |
| 60 | function validateLogger (logger, strict) { |
| 61 | const methods = ['info', 'error', 'debug', 'fatal', 'warn', 'trace', 'child'] |
| 62 | const missingMethods = logger |
| 63 | ? methods.filter(method => !logger[method] || typeof logger[method] !== 'function') |
| 64 | : methods |
| 65 | |
| 66 | if (!missingMethods.length) { |
| 67 | return true |
| 68 | } else if ((missingMethods.length === methods.length) && !strict) { |
| 69 | return false |
| 70 | } else { |
| 71 | throw FST_ERR_LOG_INVALID_LOGGER(missingMethods.join(',')) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | function createLogger (options) { |
| 76 | if (options.logger && options.loggerInstance) { |
no outgoing calls
no test coverage detected