You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
856 B
37 lines
856 B
7 months ago
|
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 <me@herr-hase.wtf>
|
||
|
* @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
|