Abrar
Abrar7mo ago

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' ...
}
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: ```JS...
Jump to solution
2 Replies
Solution
anish
anish7mo ago
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' ...
}
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!
Abrar
AbrarOP7mo ago
thanks I did something similar, just thought there was a cleaner way of declaring the logger to global scope so don't have to pass it into each function in the script as a param