import dayjs from 'dayjs' ; import colors = require ( 'colors' ) ; import { CQLog } from '@/models' ; export param { ( Date | number | string ) } date param { string } pattern returns { string } export function timeFormat ( date = Date . now ( ) , pattern = 'YYYY-MM-DD HH:mm:ss' ) { let dateTime = date ; if ( typeof date === 'number' ) { if ( date < 1e10 ) { dateTime = date * 1000 ; } } return dayjs ( dateTime ) . format ( pattern ) ; } export param { string } msg param { number } level export function printTime ( msg , level = CQLog . LOG_DEBUG ) { const time = timeFormat ( Date . now ( ) , 'HH:mm:ss.SSS' ) ; switch ( level ) { case CQLog . LOG_DEBUG : console . log ( time , '->' , colors . gray ( msg ) ) ; break ; case CQLog . LOG_INFO : console . log ( time , '->' , msg ) ; break ; case CQLog . LOG_INFO_SUCCESS : console . log ( time , '->' , colors . cyan ( msg ) ) ; break ; case CQLog . LOG_INFO_RECV : console . log ( time , '->' , colors . blue ( msg ) ) ; break ; case CQLog . LOG_INFO_SEND : console . log ( time , '->' , colors . green ( msg ) ) ; break ; case CQLog . LOG_WARNING : console . log ( time , '->' , colors . yellow ( msg ) ) ; break ; case CQLog . LOG_ERROR : console . log ( time , '->' , colors . red ( msg ) ) ; break ; case CQLog . LOG_FATAL : console . log ( time , '->' , colors . magenta ( msg ) ) ; break ; } }