cloudfunctions/SegmentPortraitPic/node_modules/@cloudbase/node-sdk/src/log/index.ts

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

import { E } from '../utils/utils'
import { ERROR } from '../const/code'
import { CloudBase } from '../cloudbase'

/**
 *
 *
 * @class Log
 */
export class Log {
    public isSupportClsReport: boolean
    private src

    public constructor() {
        const { _SCF_TCB_LOG } = CloudBase.getCloudbaseContext()
        this.src = 'app'
        this.isSupportClsReport = true
        if (`${_SCF_TCB_LOG}` !== '1') {
            this.isSupportClsReport = false
        } else if (!(console as any).__baseLog__) {
            this.isSupportClsReport = false
        }

        if (!this.isSupportClsReport) {
            // 当前非tcb scf环境  log功能会退化为console
            console.warn(
                '请检查您是否在本地环境 或者 未开通高级日志功能,当前环境下无法上报cls日志,默认使用console'
            )
        }
    }

    /**
     *
     *
     * @param {*} logMsg
     * @param {*} logLevel
     * @returns
     * @memberof Log
     */
    public transformMsg(logMsg) {
        // 目前logMsg只支持字符串value且不支持多级, 加一层转换处理
        let realMsg = {}

        realMsg = { ...realMsg, ...logMsg }
        return realMsg
    }

    /**
     *
     *
     * @param {*} logMsg
     * @param {*} logLevel
     * @memberof Log
     */
    public baseLog(logMsg, logLevel) {
        // 判断当前是否属于tcb scf环境

        if (Object.prototype.toString.call(logMsg).slice(8, -1) !== 'Object') {
            throw E({
                ...ERROR.INVALID_PARAM,
后面还有 59 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。