text: // External module imports
  const morgan = require('morgan');
  
  // Internal module imports
  const config = require('./config');
  const logger = require('./logger');
  
  morgan.token('message', (req, res) => res.locals.errorMessage || '');
  
  const getIpFormat = () =>
    config.env === 'production' ? ':remote-addr - ' : '';
  const successResponseFormat = `${getIpFormat()}:method :url :status - :response-time ms`;
  const errorResponseFormat = `${getIpFormat()}:method :url :status - :response-time ms - message: :message`;
  
  const successHandler = morgan(successResponseFormat, {
    skip: (req, res) => res.statusCode >= 400,
    stream: { write: (message) => logger.info(message.trim()) },
  });
  
  const errorHandler = morgan(errorResponseFormat, {
    skip: (req, res) => res.statusCode < 400,
    stream: { write: (message) => logger.error(message.trim()) },
  });
  
  // Module exports
  module.exports = {
    successHandler,
    errorHandler,
  };
  