file import { VERSION } from "../config/global-config" ; const canIUseLogManage = wx . canIUse ( "getLogManager" ) ; const logger = canIUseLogManage ? wx . getLogManager ( { level : 0 } ) : null ; var realtimeLogger = wx . getRealtimeLogManager ? wx . getRealtimeLogManager ( ) : null ; param { * } Date export function formatTime ( date ) { const year = date . getFullYear ( ) ; const month = date . getMonth ( ) + 1 ; const day = date . getDate ( ) ; const hour = date . getHours ( ) ; const minute = date . getMinutes ( ) ; const second = date . getSeconds ( ) ; return ( [ year , month , day ] . map ( formatNumber ) . join ( "/" ) + " " + [ hour , minute , second ] . map ( formatNumber ) . join ( ":" ) ) ; } const formatNumber = ( n ) => { const str = n . toString ( ) ; return str [ 1 ] ? str : "0" + str ; } ; param { string } file param { ... any } arg export function DEBUG ( file , ... args ) { console . debug ( file , " | " , ... args ) ; if ( canIUseLogManage ) { logger ! . debug ( `[${ VERSION }]` , file , " | " , ... args ) ; } realtimeLogger && realtimeLogger . info ( `[${ VERSION }]` , file , " | " , ... args ) ; } param { string } file param { string } func param { ... any } arg export function RUN ( file , ... args ) { console . log ( file , " | " , ... args ) ; if ( canIUseLogManage ) { logger ! . log ( `[${ VERSION }]` , file , " | " , ... args ) ; } realtimeLogger && realtimeLogger . info ( `[${ VERSION }]` , file , " | " , ... args ) ; var logs = wx . getStorageSync ( "logs" ) || [ ] ; logs . unshift ( `${ formatTime ( new Date ( ) ) } ${ file } | ${ args [ 0 ] }` ) ; wx . setStorageSync ( "logs" , logs ) ; } param { string } file param { string } func param { ... any } arg export function ERROR ( file , ... args ) { console . error ( file , " | " , ... args ) ; if ( canIUseLogManage ) { logger ! . warn ( `[${ VERSION }]` , file , " | " , ... args ) ; } if ( realtimeLogger ) { realtimeLogger . error ( `[${ VERSION }]` , file , " | " , ... args ) ; if ( realtimeLogger . setFilterMsg ) { try { realtimeLogger . setFilterMsg ( `[${ VERSION }] ${ file } ${ JSON . stringify ( args ) }` ) ; } catch ( e ) { realtimeLogger . setFilterMsg ( `[${ VERSION }] ${ file }` ) ; } } } } export function getLogger ( fileName ) { return { DEBUG : function ( ... args ) { DEBUG ( fileName , ... args ) ; } , RUN : function ( ... args ) { RUN ( fileName , ... args ) ; } , ERROR : function ( ... args ) { ERROR ( fileName , ... args ) ; } } ; }