-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from KotRikD/chore/replace-logger
Remove `winston`
- Loading branch information
Showing
20 changed files
with
120 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
}, | ||
"dependencies": { | ||
"adm-zip": "^0.5.10", | ||
"dotenv": "^16.0.3", | ||
"winston": "^3.8.2" | ||
"dotenv": "^16.0.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
import winston, { format, transports } from 'winston'; | ||
|
||
import { config } from './config'; | ||
|
||
const { timestamp, label, printf } = format; | ||
const colors = { | ||
info: '\x1b[1m\x1b[40m\x1b[42m', | ||
error: '\x1b[1m\x1b[37m\x1b[41m', | ||
debug: '\x1b[1m\x1b[37m\x1b[44m', | ||
warn: '\x1b[1m\x1b[40m\x1b[43m', | ||
reset: '\x1b[0m', | ||
grey: '\x1b[90m' | ||
}; | ||
|
||
function colorText(status: string, ...anything: any) { | ||
const colorCode = colors[status] || colors.reset; | ||
const timestamp = new Date().toISOString().split('T')[1].replace('Z', ''); | ||
|
||
const customFormat = printf(({ level, message, label, timestamp }) => { | ||
return `${timestamp} [${label}] ${level}: ${message}`; | ||
}); | ||
const time = `${colors.grey}${timestamp}${colors.reset}`; | ||
console.log( | ||
time, | ||
`${colorCode} ${status.toUpperCase()} ${colors.reset}`, | ||
...anything | ||
); | ||
} | ||
|
||
export const configureLogger = () => | ||
winston.configure({ | ||
level: config.debugLogging ? 'debug' : 'info', | ||
transports: [ | ||
// | ||
// - Write to all logs with specified level to console. | ||
new transports.Console({ | ||
format: format.combine( | ||
format.colorize(), | ||
label({ label: 'tosu' }), | ||
timestamp(), | ||
customFormat | ||
) | ||
}) | ||
] | ||
}); | ||
export const wLogger = { | ||
info: (...args: any) => colorText('info', ...args), | ||
debug: (...args: any) => { | ||
if (config.debugLogging != true) return; | ||
|
||
export const wLogger = winston; | ||
colorText('debug', ...args); | ||
}, | ||
error: (...args: any) => colorText('error', ...args), | ||
warn: (...args: any) => colorText('warn', ...args) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.