Nodejs - How to log to the log file configured in max parameters?
Hello,
With node 4 max, I know how to log into the max console with maxApi.post("message")
I also need to log into the logging file configured in Max parameters.
I tried "console.log('message')" but my messages are not present in the logging file.
The logging file only contains the fact that my nodejs script have been started.
Thanks
I assume you mean the Node Debug log file that is available via the settings? I guess that lacks a bit of an explanation, but it is not expected that your output finds its way there. This setting is only present to allow logging / debugging of the N4M process startup and communication.
To log to a file (and in your format) please use a different approach by just writing to a file by yourself or using one of the available npm logging packages
Thanks for your help.
I ended-up using "winston" and log into a separate file indeed.
But now I have two separate files to monitor while developing. I would rather have a unified logger.
Sure thing.
Usually there shouldn't be a real need to keep an eye on the N4M generated log file for you. It logs Node For Max process management events and really is meant to debug problems in the overall N4M infrastructure, when node.script is acting unexpectedly.
Most of the application relevant information can be consumed via node.script's right debugging outlet and with the help of node.debug it becomes a bit more accessible even.
I'd advocate this separation as your custom application logic / logging is somewhat decoupled and different from the general N4M one, especially as the latter will be filled and used by all instances of node.script in your patch
I never looked at that right outlet. If I can get syntax errors then it's cool. But right now I only get them in the n4m log file.
The usual development setup for any language is to have boh syntax errors and logic errors for all threads (prefixed with thread/node.script name) in one console or file so there is only one place to look at at any moment to see if anything is unusual. Anything less than that makes you loose time.
It's quite difficult to do that with max and max 4 live when it should ideally be a given.
Please refer to the error tab of the node.script help file. You will see that with the help of node.debug and a connection to the right outlet of a node.script object you receive the full error message on syntax errors etc in the code used for your node.script.
I will try that thanks
I just had a look.
I can't find a way to get errors such as "ReferenceError" and other syntax errors inside the Max Console.
It seems the only way is to have a bpatcher/node.debug object that displays the stack trace.
I need these errors to be either in a file or in the max console so I can look at them in Ableton without having to add a bpatcher/node.debug object in the Ableton device.
Well as said, the node.script object gives that data out of the right outlet. The node.debug utility doesn't do anything magical and is more of a convenience helper. If you have more specific requirements, such as the ones you are describing here, then how you might just have to patch that around the right outlet of your node.script.
Take a look at the node.script lifecycle Documentation here: https://docs.cycling74.com/max8/vignettes/08_n4m_lifecycle
The following simple patch shows how you can route the error termination messages to the Max console.