implemented new logging system in first iteration
This commit is contained in:
@@ -39,7 +39,6 @@ export async function insertMemberRank(member_id: number, rank_id: number, date?
|
||||
export async function batchInsertMemberRank(promos: BatchPromotionMember[], author: number) {
|
||||
try {
|
||||
var con = await pool.getConnection();
|
||||
console.log(promos);
|
||||
promos.forEach(p => {
|
||||
con.query(`CALL sp_update_member_rank(?, ?, ?, ?, ?, ?)`, [p.member_id, p.rank_id, author, author, "Rank Change", toDateTime(new Date(p.start_date))])
|
||||
});
|
||||
@@ -70,7 +69,7 @@ export async function getPromotionHistorySummary(page: number = 1, pageSize: num
|
||||
|
||||
let promoList: PromotionSummary[] = await pool.query(sql, [pageSize, offset]) as PromotionSummary[];
|
||||
|
||||
let loaCount = Number((await pool.query(`SELECT
|
||||
let rowCount = Number((await pool.query(`SELECT
|
||||
COUNT(*) AS total_grouped_days_count
|
||||
FROM
|
||||
(
|
||||
@@ -79,10 +78,9 @@ export async function getPromotionHistorySummary(page: number = 1, pageSize: num
|
||||
WHERE reason = 'Rank Change'
|
||||
) AS grouped_days;`))[0]);
|
||||
|
||||
console.log(loaCount);
|
||||
let pageCount = loaCount / pageSize;
|
||||
let pageCount = rowCount / pageSize;
|
||||
|
||||
let output: PagedData<PromotionSummary> = { data: promoList, pagination: { page: page, pageSize: pageSize, total: loaCount, totalPages: pageCount } }
|
||||
let output: PagedData<PromotionSummary> = { data: promoList, pagination: { page: page, pageSize: pageSize, total: rowCount, totalPages: pageCount } }
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
||||
export type LogDepth = 'normal' | 'verbose';
|
||||
export type LogType = 'http' | 'app';
|
||||
export type LogType = 'http' | 'app' | 'auth';
|
||||
|
||||
export interface LogHeader {
|
||||
timestamp: string;
|
||||
@@ -27,7 +27,6 @@ function shouldLog(depth: LogDepth) {
|
||||
|
||||
function emitLog(header: LogHeader, payload: LogPayload = {}) {
|
||||
if (!shouldLog(header.depth)) return;
|
||||
console.log(header, payload);
|
||||
|
||||
const logLine = { ...header, ...payload };
|
||||
console.log(JSON.stringify(logLine));
|
||||
@@ -51,19 +50,19 @@ export const logger = {
|
||||
emitLog(header, payload);
|
||||
},
|
||||
|
||||
info(type: string, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
|
||||
info(type: LogType, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
|
||||
this.log('info', type, message, data, depth, context);
|
||||
},
|
||||
|
||||
debug(type: string, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
|
||||
debug(type: LogType, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
|
||||
this.log('debug', type, message, data, depth, context);
|
||||
},
|
||||
|
||||
warn(type: string, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
|
||||
warn(type: LogType, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
|
||||
this.log('warn', type, message, data, depth, context);
|
||||
},
|
||||
|
||||
error(type: string, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
|
||||
error(type: LogType, message: string, data?: Record<string, any>, depth: LogDepth = 'normal', context?: Partial<LogHeader>) {
|
||||
this.log('error', type, message, data, depth, context);
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user