-
-
Notifications
You must be signed in to change notification settings - Fork 80
DebugAndLog
There are many ways to debug your NPL scripts, including printing logs, via NPL Code Wiki, or via IDE like visual studio or vscode, etc.
log.txt
file is the most important place to look for errors. When your application starts, NPL runtime will create a new log.txt
in the current working directory.
The entire Unix system is built on top of the philosophy of rule of silence, which advocate every program to output nothing to standard output unless absolutely necessary.
So by default, NPL runtime output nothing to its standard output. All NPL output API like log
, print
, echo
write content to log.txt
instead of standard output. There is only one hidden API io.write
which can be used to write to standard output.
By default, NPL runtime and its libraries output many info to log files. This log file can grow big if your server runs for days. There are two ways to deal with it: one is to use a timer (or external shell script) to backup or redirect log.txt
to a different file everyday; second is to change the default log level to error
, which only output fatal errors to log.txt
. Application developers can also write their own logs to several files simultaneously, please see script/ide/log.lua
for details.
When application starts, one can also change the default log file name, or whether it will overwrite existing log.txt
or append to it. Please refer to log interface C++ API for details.
The default log level of NPL is TRACE
, which will write lots of logs to log.txt
. At development time, it is good practice to keep this file open in a text editor that can automatically refresh when file content is changed.
When you feel something goes wrong, search for error
or runtime error
in log.txt
. NPL Code Wiki may provide a filter, where you can filter logs via GUI.
Many script programmers prefer to insert echo({params, ...})
in code to output debug info to log.txt
, and when code is working, these echo
lines are commented out.
A good practice is to insert permanent log line with debug level set to debug
like LOG.std(nil, "debug", "modulename", "some text", ...)
.
Sometimes inserting temporary log lines into code can be inefficient. One can also use NPL HTTP debugger to debug code via HTTP in a HTML5 web browser with nice GUI. NPL HTTP Debugger allows you to debug remote process, such as debugging linux/android/ios NPL process on a windows or mac computer.
We also provide open source NPL debugger plugins that is integrated with visual studio and vscode, see NPLCodeWiki and InstallGuide for details.
Download Paracraft | ParacraftSDK | copyright by tatfook 2016 | upload image