AbrarA

Logging witihin NodeLogic

This is probably a very basic Javascript question...

Consulted he documentation and yes there is logging but it is only available (scoped) in the default export function.. I want to log in the other functions... how do I get this to work?

Consider the following:

export default async function (
  { inputData }: NodeInputs, // Access values of node input params
  { logging, env }: NodeScriptOptions,
): NodeOutput {
  /* Log values while executing the node/workflow */
  logging.log(">> Hello From Default!");
  someFunc();
 
  return {}
} 

function someFunc() {
  // This is what i want to do..
  logging.log(">> >> Hello from someFunc()");
  // I keep getting 'logging is not defined' ...
}


Thanks in advance!
Solution
Hey @Abrar, you can do this by passing the logging as a parameter to other functions.

Check this updated code:

export default async function (
  { inputData }: NodeInputs, // Access values of node input params
  { logging, env }: NodeScriptOptions,
): NodeOutput {
  /* Log values while executing the node/workflow */
  logging.log(">> Hello From Default!");
  someFunc(logging);
 
  return {}
} 

function someFunc(logging: NodeScriptOptions["logging"]) {
  // This is what i want to do..
  logging.log(">> >> Hello from someFunc()");
  // I keep getting 'logging is not defined' ...
}


Hope this helps!
Was this page helpful?