Cloudcode Logs

Hi All

In cloudcode we have have a cloudcode task with your typical index.js file.

In running the task we call other sub tasks within the primary task, for example in index.js we would require sub_task.js which then runs and has its own executable code.

The challenge is then with logging.

In Cloudcode invocation history the logs from the primary task are visible but any logs in the sub task are seemingly not present.

My expectation would be that logs in sub tasks would be included in the primary tasks logs.

By way of example:

Any console.log in index.js reflects in the invocation history log, whereas any log in promissory.js does not.

Am I missing something or am I simply looking in the wrong place?

image

Hi Matthew,

Just a few quick questions:

  • How are you exporting from promissory.js (i.e. what does the syntax look like)?

  • How are you requiring the file in index.js (i.e. what does the syntax look like)?

  • Where is the console.log() invocation in promissory.js that you are expecting to see, and is it contained within a function that is in fact invoked somewhere?

For example, your index.js might look something like this:

const promissory = require("./promissory.js")

export async function run() {
    promissory.logger();
    
    await promissory.asyncLogger();
    
    await promissory.logAll();
}

And then your promissory.js file would look something like this:

async function asyncLogger(){
    console.log("Logging from async logger function!")
}

function logger(){
    console.log("Logging from logger now!")
}

async function logAll(){
    console.log("Now calling both log functions again from logAll...")
    await asyncLogger();
    logger();
    console.log("Done!")
}

module.exports = {logger: logger, asyncLogger: asyncLogger, logAll: logAll}

You can export with a different syntax (e.g. export {asyncLogger, logger, logAll}) but if the syntax is incorrect, then the references to the required/imported file will not work.

Keep in mind that you will want to ensure that your use of console.log() is contained within a function that is either included in the export, or is contained by a function that is invoked by another function included in the export. If the console.log() does not fall within the scope of the function(s) that are called, then it will not be included in the task logs when the task is executed.