MCPcopy
hub / github.com/fastify/fastify / validateLogger

Function validateLogger

lib/logger-factory.js:60–73  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

58 * missing required methods.
59 */
60function 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
75function createLogger (options) {
76 if (options.logger && options.loggerInstance) {

Callers 2

createChildLoggerFunction · 0.85
createLoggerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected