import { createLogger } from '@hyext/utils'
import { getTime } from './shared'

const timestamp = Date.now()

function safetyStringify(v: any) {
  try {
    return JSON.stringify(v)
  } catch (error) {
    return 'stringify error'
  }
}

const logger = createLogger({
  onAfter(logInfo) {
    global.hyExt.logger.info(logInfo.desc + ' ' + safetyStringify(logInfo.data))
  },
  prefix() {
    return `exe-game-template * date:${getTime()} sessionId:${timestamp} -`
  },
  enableLog() {
    // if (process.env.HYEXT_BUILD_ENV === 'production') return false
    return true
  },
})

export default logger
