如何angularjs将日志写入文件

How to angularjs write log to file?

本文关键字:文件 日志 angularjs 如何      更新时间:2023-09-26

我有问题吗?在Angularjs项目中,我可以使用什么日志来写入文件$Angular或log4javascript的日志。我有Angularjs:的$log的代码配置

$log.getInstance = function (context) {
        return {
            log: enhanceLogging($log.log, context),
            info: enhanceLogging($log.info, context),
            warn: enhanceLogging($log.warn, context),
            debug: enhanceLogging($log.debug, context),
            error: enhanceLogging($log.error, context)
        };
    };
    function enhanceLogging(loggingFunc, context) {
        return function () {
            var modifiedArguments = [].slice.call(arguments);
            modifiedArguments[0] = [moment().format("dddd h:mm:ss a") + '::[' + context + ']: '] + modifiedArguments[0];
            loggingFunc.apply(null, modifiedArguments);
        };
    }

它正在工作,但它只写入控制台,现在我想将日志输出到文件中?

客户端Javascript无法访问磁盘上的文件。因此,不可能写入日志文件。

然而,你可以使用类似哨兵的东西来记录你的消息。