Action

eu.42sol: install _js/debug_logilfe.js

Last update almost 4 years ago - Unlisted

Version: 2020.01 (unstable/alpha)

Improved version of “Debug” action.

Features:
- reroute console.log to a iCloud file debug_{date}.txt in iCloud Drafts directory
- this action creates a file debug_log_file.js in your iCloud Drafts directory _js
- copy content of the file to create a special script action

Improvements:
- add script to a library action in a drafts action …
- automatic / better line handling (manual setting of an integer does not look fine to me)

Steps

  • file

    fileNameTemplate
    debug_log_file.js
    folderTemplate
    _js
    template
    // Sample. To be used anywhere in code:
    // code … 
    // console.log(10, 'sample: open this script for instructions!', 108, ['string', 15, false]); 
    // code … 
    //-------------------------------------------------------------
    // debug_log_file.js
    // Captures console.log() to file:
    const _show_allert = false
    
    var captLog = '';
    var _clearLog = false; // clear log on first run
    
    (function(){
        var oldLog = console.log;
        console.log = function (message) {
            captLog = Array.prototype.join.call(arguments, '\n\t');
            oldLog.apply(console, arguments);
            writeLog()
        };
    })();
    
    function writeLog() {
      // function to send log to external file
      const now = new Date();
      const tm = now.toString("yyyy-MM-dd HH:mm");
      
      let msg = ' line: ' + captLog;
      let shortMsg = msg.split('\n\t').join(': ').slice(0, 20);
      
      // For interactive log, use either (or none) of these two lines:
      // app.displayInfoMessage(shortMsg)
      if(_show_allert) alert(msg)
      
      let path = '/debug_log' + new Date().toString('yyyy-MM-dd') + '.txt';
      let fm = FileManager.create(false);
      log = fm.readString(path);
      if (_clearLog) {
        log = tm + msg; // new log
        _clearLog = false;
      } else {
        log = log + '\n' + tm + ': ' + msg; // append to log
      }
      let success = fm.writeString(path, log);
    }
    // -------------- end of file --------------
    
    local
    false
    writeType
    replace

Options

  • After Success Nothing
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.