import pino from 'pino' import pretty from 'pino-pretty' import dayjs from 'dayjs' import { mkdirSync } from "node:fs" import slug from 'slug' /** * Wrapper for logger * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License * @link https://git.node001.net/HerrHase/super-hog.git * */ function logger(slug?: string) { let destination = './storage/logs/' // if name is set, adding name as directory if (slug) { destination += slug + '/' mkdirSync(destination, { recursive: true }) } destination += dayjs().format('DD-MM-YYYY') + '.log' return pino({ timestamp: () => { return `, "time":"${new Date(Date.now()).toISOString()}"` }, }, pino.destination(destination) ) } export default logger