Added winston for logging.
This commit is contained in:
44
src/util/LoggerUtil.ts
Normal file
44
src/util/LoggerUtil.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { createLogger, format, transports, Logger } from 'winston'
|
||||
import { SPLAT } from 'triple-beam'
|
||||
import moment from 'moment'
|
||||
import { inspect } from 'util'
|
||||
|
||||
export class LoggerUtil {
|
||||
|
||||
public static getLogger(label: string): Logger {
|
||||
return createLogger({
|
||||
format: format.combine(
|
||||
format.label(),
|
||||
format.colorize(),
|
||||
format.label({ label }),
|
||||
format.printf(info => {
|
||||
if(info[SPLAT]) {
|
||||
if(info[SPLAT].length === 1 && info[SPLAT][0] instanceof Error) {
|
||||
const err = info[SPLAT][0] as Error
|
||||
if(info.message.length > err.message.length && info.message.endsWith(err.message)) {
|
||||
info.message = info.message.substring(0, info.message.length-err.message.length)
|
||||
}
|
||||
} else if(info[SPLAT].length > 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
info.message += ' ' + info[SPLAT].map((it: any) => {
|
||||
if(typeof it === 'object' && it != null) {
|
||||
return inspect(it, false, 4, true)
|
||||
}
|
||||
return it
|
||||
}).join(' ')
|
||||
}
|
||||
}
|
||||
if(typeof info.message === 'object') {
|
||||
info.message = inspect(info.message, false, 4, true)
|
||||
}
|
||||
return `[${moment().format('YYYY-MM-DD hh:mm:ss').trim()}] [${info.level}] [${info.label}]: ${info.message}${info.stack ? `\n${info.stack}` : ''}`
|
||||
})
|
||||
),
|
||||
level: 'debug',
|
||||
transports: [
|
||||
new transports.Console()
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
import { spawn } from 'child_process'
|
||||
import { join } from 'path'
|
||||
import { JavaUtil } from './javautil'
|
||||
import { LoggerUtil } from './LoggerUtil'
|
||||
|
||||
export class PackXZExtractWrapper {
|
||||
|
||||
private static readonly logger = LoggerUtil.getLogger('PackXZExtract')
|
||||
|
||||
public static getPackXZExtract(): string {
|
||||
return join(process.cwd(), 'libraries', 'java', 'PackXZExtract.jar')
|
||||
}
|
||||
@@ -28,14 +31,14 @@ export class PackXZExtractWrapper {
|
||||
command,
|
||||
paths.join(',')
|
||||
])
|
||||
child.stdout.on('data', (data) => console.log('[PackXZExtract]', data.toString('utf8').trim()))
|
||||
child.stderr.on('data', (data) => console.error('[PackXZExtract]', data.toString('utf8').trim()))
|
||||
child.stdout.on('data', (data) => PackXZExtractWrapper.logger.info(data.toString('utf8').trim()))
|
||||
child.stderr.on('data', (data) => PackXZExtractWrapper.logger.error(data.toString('utf8').trim()))
|
||||
child.on('close', code => {
|
||||
console.log('[PackXZExtract]', 'Exited with code', code)
|
||||
PackXZExtractWrapper.logger.info('Exited with code', code)
|
||||
resolve()
|
||||
})
|
||||
child.on('error', (err) => {
|
||||
console.log('[PackXZExtract]', 'Error during process execution', err)
|
||||
PackXZExtractWrapper.logger.info('Error during process execution', err)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import Axios from 'axios'
|
||||
import { PromotionsSlim } from '../model/forge/promotionsslim'
|
||||
import { MinecraftVersion } from './MinecraftVersion'
|
||||
import { LoggerUtil } from './LoggerUtil'
|
||||
|
||||
export class VersionUtil {
|
||||
|
||||
private static readonly logger = LoggerUtil.getLogger('VersionUtil')
|
||||
|
||||
public static readonly PROMOTION_TYPE = [
|
||||
'recommended',
|
||||
'latest'
|
||||
@@ -54,8 +57,8 @@ export class VersionUtil {
|
||||
const res = await VersionUtil.getPromotionIndex()
|
||||
let version = res.promos[`${minecraftVersion}-${workingPromotion}`]
|
||||
if (version == null) {
|
||||
console.warn(`No ${workingPromotion} version found for Forge ${minecraftVersion}.`)
|
||||
console.warn('Attempting to pull latest version instead.')
|
||||
VersionUtil.logger.warn(`No ${workingPromotion} version found for Forge ${minecraftVersion}.`)
|
||||
VersionUtil.logger.warn('Attempting to pull latest version instead.')
|
||||
version = res.promos[`${minecraftVersion}-latest`]
|
||||
if (version == null) {
|
||||
throw new Error(`No latest version found for Forge ${minecraftVersion}.`)
|
||||
|
||||
Reference in New Issue
Block a user