SetLogParams

From Avisynth wiki
Revision as of 17:23, 16 June 2020 by Reel.Deal (Talk | contribs)

Jump to: navigation, search
AVS+
This feature is specific to AviSynthPlus.

It is not supported in other AviSynth versions.

Contents

Starting with r2069, AviSynth+ received a logging facility. You can enable it using SetLogParams at the beginning of your script.
Log messages can be output by scripts using LogMsg.

If logging is enabled, AviSynth+ will output log messages by itself too. It will automatically log errors, and will issue warnings and notes to the user to inform him about potential problems, buggy plugins, suboptimal settings et cetera. There are a couple of these log messages and they come in various colors.


Syntax and Parameters

SetLogParams

Sets a file path for a log file, used by LogMsg and internal error reporting.


SetLogParams (string "target", int "level")


string  target =
target names a file which will be created when the script loads. If attempting to create or write to target fails, the script will raise an error immediately. If the file exists, new log entries will be appended to the end.
target can be either "stderr", "stdout", or a path to a file, if omitted, target defaults to stderr.


int  level = 0
level sets the log verbosity; each level with increasing verbosity:
  • 1 : LOG_ERROR
  • 2 : LOG_WARNING
  • 3 : LOG_INFO
  • 4 : LOG_DEBUG
By default, logging is disabled (0).


LogMsg

Creates a new log entry.


LogMsg (string msg, int level)


string   =
msg (required) specifies the log message.


int   =
level (required) specifies the log entry level: see SetLogParams above.


Exampls

## creating file and set path for future log entries:
SetLogParams("<path>\_test1.log", LOG_INFO)

...log contents:
(empty)
## logging an INFO message:
SetLogParams("<path>\_test2.log", LOG_INFO)
LogMsg("this is a test", LOG_INFO)

log contents:
---------------------------------------------------------------------
INFO: this is a test
## logging a script error:
SetLogParams("<path>\_test3.log", LOG_INFO)
foo("bar") ## ERROR!

...log contents (redundant entries are common):
ERROR: Script error: There is no function named 'foo'.
---------------------------------------------------------------------
ERROR: Script error: There is no function named 'foo'.
(<path>\_test.avs, line 35)
## logging INFO context for script error:
SetLogParams("<path>\_test4.log", LOG_INFO)
function MyFunction(clip C)
{
    C
    try {
        foo("bar") ## ERROR!
    } catch (err_msg) {
        msg2 = "Error in MyFunction: "
        LogMsg(Time("%Y-%m-%d %I:%M:%S %p, %z") + ": " + msg2, LOG_INFO)
        #Assert(false, msg2 + err_msg) ## optional: stop script, else continue
    }
    return Last
}

log contents (redundant entries omitted):
---------------------------------------------------------------------
ERROR: Script error: There is no function named 'foo'.
(<path>\_test.avs, line 54)
---------------------------------------------------------------------
INFO: 2017-11-12 11:03:41 AM, -0500: Error in MyFunction:
(<path>\_test.avs, line 54)


Changes

xxxxx xxxxx
Personal tools