1
0
mirror of https://github.com/dzeiocom/libs.git synced 2025-04-23 19:32:14 +00:00

Merge branch 'master' of github.com:dzeiocom/libs

This commit is contained in:
Florian Bouillon 2021-09-05 14:28:36 +02:00
commit daed0b82e6
Signed by: Florian Bouillon
GPG Key ID: 50BD648F12C86AB6
4 changed files with 21632 additions and 6 deletions

21608
packages/logger/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@dzeio/logger",
"version": "2.0.4",
"version": "2.1.0",
"description": "My Personnal Logger",
"repository": {
"type": "git",
@ -18,11 +18,11 @@
"@typescript-eslint/eslint-plugin": "^4.5.0",
"@typescript-eslint/parser": "^4.5.0",
"eslint": "^7.4.0",
"parcel": "^1.12.4",
"parcel": "1.12.3",
"typescript": "^4.0.3"
},
"scripts": {
"prepublishOnly": "yarn build",
"prepublishOnly": "npm run build",
"build": "parcel build src/index.ts --out-file browser.js --experimental-scope-hoisting && tsc",
"test": "ts-node test"
}

View File

@ -22,6 +22,14 @@ export default class Logger implements Console {
*/
private static loggers: Array<Logger> = []
/**
*Define if you want a timestamp with your logs
*
* @static
* @memberof Logger
*/
public static timestamp = false
/**
* Console memory
* (IDK what it is)
@ -367,7 +375,16 @@ export default class Logger implements Console {
}
const res: Array<any> = [
`${this.blackOrWhite('[ ')}${spacers[0]}${blue(prefix)}${spacers[1]}${this.blackOrWhite(' ]')}:`
].concat(
]
if (Logger.timestamp) {
const now = new Date()
const h = now.getHours() >= 10 ? now.getHours().toString() : `0${now.getHours()}`
const m = now.getMinutes() >= 10 ? now.getMinutes().toString() : `0${now.getMinutes()}`
const s = now.getSeconds() >= 10 ? now.getSeconds().toString() : `0${now.getSeconds()}`
res.unshift(`${this.blackOrWhite('<')}${yellow(h)}:${yellow(m)}:${yellow(s)}${this.blackOrWhite('>')}`)
}
return res.concat(
message.map((el) => {
if (typeof el === 'object') {
return el
@ -381,7 +398,6 @@ export default class Logger implements Console {
return typeof el !== 'string' ? yellow(el.toString()) : green(el)
})
)
return res
}
/**

View File

@ -1,4 +1,6 @@
import { logger as console } from '../src/Logger'
import Logger, { logger as console } from '../src/Logger'
Logger.timestamp = true
/**
* This test file is simple :D