5

I have a question? In Angularjs project, what log I can use to write to file? $log of Angular or log4javascript. I have code config for $log of Angularjs:

$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);
        };
    }

It's working but it only write to console and now I want log output to file?

1
  • If you want to log it into files, you have to send the logs to an API which will write the logs into files. Commented May 6, 2016 at 8:39

1 Answer 1

2

Clientside Javascript does not have access to files on disk. So it is impossible to write to a logfile.

However you could use something like Sentry to log your messages.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I will send log to server and server write it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.