Update envars to new node SDK format

This commit is contained in:
Tuan Dang
2023-04-22 16:20:33 +03:00
parent 3846c42c00
commit e1bf31b371
44 changed files with 223 additions and 229 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ export const testWorkspaceKeyId = "63cf48f0225e6955acec5eff"
export const plainTextWorkspaceKey = "543fef8224813a46230b0a50a46c5fb2"
export const createTestUserForDevelopment = async () => {
if (getNodeEnv() === "development" || getNodeEnv() === "test") {
if ((await getNodeEnv()) === "development" || (await getNodeEnv()) === "test") {
const testUser = {
_id: testUserId,
email: testUserEmail,
+10 -12
View File
@@ -12,7 +12,7 @@ const logFormat = (prefix: string) => combine(
printf((info) => `${info.timestamp} ${info.label} ${info.level}: ${info.message}`)
);
const createLoggerWithLabel = (level: string, label: string) => {
const createLoggerWithLabel = async (level: string, label: string) => {
const _level = level.toLowerCase() || 'info'
//* Always add Console output to transports
const _transports: any[] = [
@@ -25,10 +25,10 @@ const createLoggerWithLabel = (level: string, label: string) => {
})
]
//* Add LokiTransport if it's enabled
if(getLokiHost() !== undefined){
if((await getLokiHost()) !== undefined){
_transports.push(
new LokiTransport({
host: getLokiHost(),
host: await getLokiHost(),
handleExceptions: true,
handleRejections: true,
batching: true,
@@ -40,7 +40,7 @@ const createLoggerWithLabel = (level: string, label: string) => {
labels: {
app: process.env.npm_package_name,
version: process.env.npm_package_version,
environment: getNodeEnv()
environment: await getNodeEnv()
},
onConnectionError: (err: Error)=> console.error('Connection error while connecting to Loki Server.\n', err)
})
@@ -58,12 +58,10 @@ const createLoggerWithLabel = (level: string, label: string) => {
});
}
const DEFAULT_LOGGERS = {
"backend-main": createLoggerWithLabel('info', '[IFSC:backend-main]'),
"database": createLoggerWithLabel('info', '[IFSC:database]'),
}
type LoggerNames = keyof typeof DEFAULT_LOGGERS
export const getLogger = (loggerName: LoggerNames) => {
return DEFAULT_LOGGERS[loggerName]
export const getLogger = async (loggerName: 'backend-main' | 'database') => {
const logger = {
"backend-main": await createLoggerWithLabel('info', '[IFSC:backend-main]'),
"database": await createLoggerWithLabel('info', '[IFSC:database]'),
}
return logger[loggerName]
}
+2 -2
View File
@@ -81,13 +81,13 @@ export default class RequestError extends Error{
return obj
}
public format(req: Request){
public async format(req: Request){
let _context = Object.assign({
stacktrace: this.stacktrace
}, this.context)
//* Omit sensitive information from context that can leak internal workings of this program if user is not developer
if(!getVerboseErrorOutput()){
if(!(await getVerboseErrorOutput())){
_context = this._omit(_context, [
'stacktrace',
'exception',