Tuesday, October 4
Shadow

A simple, pretty and powerful logger for NodeJS with an awesome set of add-ons and features.

 * RyadPasha’s Logger
 *
 * This class is a simple, pretty and powerful logger
 * for NodeJS with an awesome set of addons and features.
 *
 * @author    Mohamed Riyad <m@ryad.me>
 * @link      RyadPasha.com
 * @copyright Copyright (C) 2022 RyadPasha. All rights reserved.
 * @license   MIT License https://opensource.org/licenses/MIT
 * @version   Release: 1.0
 * @since     6 Aug, 2022
 */

const { createLogger, transports, format } = require('winston')
const DailyRotateFile = require('winston-daily-rotate-file')

/**
 * Log Files Directory
 * The main directory where all log files will be stored.
 */
const logFilesDir = `${__dirname}/../logs`

/**
 * Log Files Name
 * Filename to be used to log to.
 *
 * This filename can include the %DATE% placeholder which will include the
 * formatted filesDatePattern at that point in the filename.
 */
const logFilesName = '%LEVEL%_%DATE%'

/**
 * Files date format
 * A string representing the moment.js date format to be used for rotating.
 *
 * The meta characters used in this string will dictate the frequency of the
 * file rotation.
 *
 * For example, if your datePattern is simply 'HH' you will end up with 24 log
 * files that are picked up and appended to every day (default: 'YYYY-MM-DD').
 */
const filesDatePattern = 'MM-YYYY'

/**
 * Max file size
 * Maximum size of the file after which it will rotate.
 *
 * This can be a number of bytes, or units of kb, mb, and gb.
 * If using the units, add 'k', 'm', or 'g' as the suffix.
 * The units need to directly follow the number.
 */
const maxFileSize = '15mb'

/**
 * Max files
 * Maximum number of logs to keep.
 *
 * If not set, no logs will be removed. This can be a number
 * of files or number of days. If using days, add 'd' as the suffix.
 *
 * It uses auditFile to keep track of the log files in a json format.
 * It won't delete any file not contained in it.
 */
const maxFiles = null

/**
 * Zipped archive
 * A boolean to define whether or not to gzip archived log files.
 */
const zippedArchive = false

/**
 * Log date format
 * A string representing the moment.js date format to be used in the log.
 */
const logDateFormat = 'YYYY-MM-DD hh:mm:ss A'

/**
 * Log date timezone
 * A string representing the timezone for the date in the log.
 *
 * Only used if there's not a logDateFormat set.
 */
const logDateTimezone = process.env.LOG_TIMEZONE || 'Asia/Dubai'

Leave a Reply