import { getMACAdress } from '../utils/util'; import baseRequest from '../utils/base.request'; import { getRunAt, getConfigByRunEnv } from './config'; export interface LogOptions { action: string; appId?: string; } /** * 记录日志 */ export default async function postLog(options: LogOptions) { const cliConfig = await getConfigByRunEnv().catch(() => { return { toolId: '', }; }); try { const VERSION = require('../../package.json').version; const data = { ideVersion: VERSION, ideType: process.env.MINIU_CLI === 'true' ? 'CLI' : getRunAt(), macAddress: getMACAdress(), os: process.platform === 'darwin' ? 'Mac' : 'Windows', toolId: cliConfig.toolId, ...options, }; // 日志发送失败暂时不处理 baseRequest({ method: 'POST', host: 'ide', path: '/ide/api/log.json', data, }).catch((e) => { console.log('日志上报失败', e); }); } catch (e) { console.log('日志上报失败', e); } }