SetLogParams

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(redirect for convenient searching)
 
(SetLogParams: add documentation for SetLogParams and LogMsg (merge docs from Internal_functions#SetLogParams and AviSynth+#Logging_Facility page.)
Line 1: Line 1:
#REDIRECT [[Internal_functions#SetLogParams]]
+
<div style="max-width:82em; min-width:42em;" >
[[Category:Redirects]]
+
{{AvsPlusFilter}}
 +
__TOC__
 +
</div>
 +
 
 +
<div style="max-width:62em; min-width:42em;" >
 +
Starting with r2069, AviSynth+ received a logging facility. You can enable it using <code>SetLogParams</code> at the beginning of your script.<br>
 +
Log messages can be output by scripts using <code>LogMsg</code>.
 +
 
 +
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.
 +
 
 +
*Source: http://forum.doom9.org/showthread.php?p=1774770#post1774770
 +
*Also see: [[Internal_functions#SetLogParams]] and [[Internal_functions#LogMsg]]
 +
</div>
 +
 
 +
 
 +
=== Syntax and Parameters ===
 +
<div style="max-width:62em; min-width:42em;" >
 +
==== SetLogParams ====
 +
Sets a file path for a log file, used by [[#LogMsg|LogMsg]] and internal error reporting.
 +
 
 +
 
 +
:{{FuncDef|SetLogParams (string "target", int "level")}}<br>
 +
<br>
 +
::{{Par2|target|string|}}
 +
:::{{FuncArg|target}} names a file which will be created when the script loads. If attempting to create or write to {{FuncArg|target}} fails, the script will raise an error immediately. If the file exists, new log entries will be appended to the end.
 +
:::{{FuncArg|target}} can be either "stderr", "stdout", or a path to a file,  if omitted, {{FuncArg|target}} defaults to [[wikipedia:Stderr|stderr]].
 +
<br>
 +
::{{Par2|level|int|0}}
 +
:::{{FuncArg|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). 
 +
<br>
 +
==== LogMsg ====
 +
Creates a new log entry.
 +
 
 +
 
 +
:{{FuncDef|LogMsg (string msg, int level)}}
 +
<br>
 +
::{{Par2||string|}}
 +
:::<code>msg</code> (required) specifies the log message.
 +
<br>
 +
::{{Par2||int|}}
 +
:::<code>level</code> (required) specifies the log entry level: see [[#SetLogParams|SetLogParams]] above.
 +
</div>
 +
<br>
 +
<div style="max-width:76em; min-width:42em;" >
 +
=== Exampls ===
 +
<pre>
 +
## creating file and set path for future log entries:
 +
SetLogParams("<path>\_test1.log", LOG_INFO)
 +
 
 +
...log contents:
 +
(empty)
 +
</pre>
 +
 
 +
<pre>
 +
## logging an INFO message:
 +
SetLogParams("<path>\_test2.log", LOG_INFO)
 +
LogMsg("this is a test", LOG_INFO)
 +
 
 +
log contents:
 +
---------------------------------------------------------------------
 +
INFO: this is a test
 +
</pre>
 +
 
 +
<pre>
 +
## 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)
 +
</pre>
 +
 
 +
<pre>
 +
## 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)
 +
</pre>
 +
</div>
 +
<br>
 +
=== Changes ===
 +
<div style="max-width:62em; min-width:42em;" >
 +
{|border=1 cellspacing=1 cellpadding=4
 +
|-
 +
| xxxxx
 +
| xxxxx
 +
|}
 +
</div>
 +
 
 
[[Category:Internal_functions]]
 
[[Category:Internal_functions]]
 +
[[Category:Avisynthplus]]

Revision as of 17:23, 16 June 2020

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