logger-factory.js — fastify Source File
Architecture documentation for logger-factory.js, a javascript file in the fastify codebase.
Entity Profile
Relationship Graph
Source Code
'use strict'
const {
FST_ERR_LOG_LOGGER_AND_LOGGER_INSTANCE_PROVIDED,
FST_ERR_LOG_INVALID_LOGGER_CONFIG,
FST_ERR_LOG_INVALID_LOGGER_INSTANCE,
FST_ERR_LOG_INVALID_LOGGER
} = require('./errors')
/**
* Utility for creating a child logger with the appropriate bindings, logger factory
* and validation.
* @param {object} context
* @param {import('../fastify').FastifyBaseLogger} logger
* @param {import('../fastify').RawRequestDefaultExpression<any>} req
* @param {string} reqId
* @param {import('../types/logger.js').ChildLoggerOptions?} loggerOpts
*
* @returns {object} New logger instance, inheriting all parent bindings,
* with child bindings added.
*/
function createChildLogger (context, logger, req, reqId, loggerOpts) {
const loggerBindings = {
[context.requestIdLogLabel]: reqId
}
const child = context.childLoggerFactory.call(context.server, logger, loggerBindings, loggerOpts || {}, req)
// Optimization: bypass validation if the factory is our own default factory
if (context.childLoggerFactory !== defaultChildLoggerFactory) {
validateLogger(child, true) // throw if the child is not a valid logger
}
return child
}
/** Default factory to create child logger instance
*
* @param {import('../fastify.js').FastifyBaseLogger} logger
* @param {import('../types/logger.js').Bindings} bindings
* @param {import('../types/logger.js').ChildLoggerOptions} opts
*
* @returns {import('../types/logger.js').FastifyBaseLogger}
*/
function defaultChildLoggerFactory (logger, bindings, opts) {
return logger.child(bindings, opts)
}
/**
* 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 meets the requirements.
*
* @throws {FST_ERR_LOG_INVALID_LOGGER} When the logger object is
* missing required methods.
*/
function validateLogger (logger, strict) {
// ... (77 more lines)
Domain
Subdomains
Source
Frequently Asked Questions
What does logger-factory.js do?
logger-factory.js is a source file in the fastify codebase, written in javascript. It belongs to the CoreKernel domain, InstanceFactory subdomain.
What functions are defined in logger-factory.js?
logger-factory.js defines 5 function(s): createChildLogger, createLogger, defaultChildLoggerFactory, now, validateLogger.
Where is logger-factory.js in the architecture?
logger-factory.js is located at lib/logger-factory.js (domain: CoreKernel, subdomain: InstanceFactory, directory: lib).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free