Merge branch 'main' into quest-file

This commit is contained in:
Lin, Hung-Shin committed 2023-11-22 11:39:24 +08:00
commit 21ca083628
46 files changed
+653 -220

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import winston from 'winston'
import config from '../config.js'
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'backend', timestamp: new Date().toISOString() },
transports: [
//
// - Write all logs with importance level of `error` or less to `error.log`
// - Write all logs with importance level of `info` or less to `combined.log`
//
new winston.transports.File({
dirname: config.log.path,
filename: 'error.log',
level: 'error',
}),
new winston.transports.File({
dirname: config.log.path,
filename: 'combined.log',
}),
],
})
//
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
//
if (process.env.NODE_ENV !== 'production') {
logger.add(
new winston.transports.Console({
format: winston.format.simple(),
})
)
}
export default logger
+2 -1
View File
@@ -3,6 +3,7 @@ import path from 'path'
import yaml from 'yaml'
import { Quest } from '@linux-odyssey/models'
import logger from './logger.js'
const questDirectory = path.join(process.cwd(), '..', 'quests')
@@ -45,7 +46,7 @@ export async function loadAndUpdateQuests() {
})
await quest.save()
} catch (error) {
console.error(`Error parsing quest ${id}:`, error.message)
logger.error(`Error parsing quest ${id}:`, error)
throw error
}
})
+4 -3
View File
@@ -1,9 +1,10 @@
import { User } from '@linux-odyssey/models'
import config from '../config.js'
import { createUser } from '../models/userManager.js'
import logger from './logger.js'
export default async function setupTest() {
console.log('Setting up test account')
logger.info('Setting up test account')
if (!(config.testing.username && config.testing.password)) {
throw new Error(
'No testing account found! Please set TESTING_USERNAME and TESTING_PASSWORD in .env'
@@ -13,10 +14,10 @@ export default async function setupTest() {
const email = `${username}@example.com`
if (await User.exists({ username })) {
console.log('Testing account already exists')
logger.info('Testing account already exists')
return
}
await createUser(username, email, { password })
console.log('Created testing account')
logger.info('Created testing account')
}