mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-24 04:44:26 +02:00
global-functions: merge $LogAnd{Error,Put} to $LogPrintExit ...
... and fix logging. Logging with severity from variable (:log $severity ...) is not possible, this is considered a syntax error. Also the 'workaround' with parsing code failed with missing message in log. The reliable code is a lot longer, so merge the two functions to save a lot of duplicate code.
This commit is contained in:
parent
6036edb506
commit
ceaa83b83e
13 changed files with 56 additions and 56 deletions
|
@ -37,8 +37,7 @@
|
|||
:global MailServerIsUp;
|
||||
:global TimeIsSync;
|
||||
:global WaitTimeSync;
|
||||
:global LogAndError;
|
||||
:global LogAndPut;
|
||||
:global LogPrintExit;
|
||||
|
||||
# url encoding
|
||||
:set UrlEncode do={
|
||||
|
@ -491,20 +490,22 @@
|
|||
}
|
||||
}
|
||||
|
||||
# log and error with same text
|
||||
:set LogAndError do={
|
||||
# log and print with same text, optionally exit
|
||||
:set LogPrintExit do={
|
||||
:local Severity [ :tostr $1 ];
|
||||
:local Message [ :tostr $2 ];
|
||||
:local Message [ :tostr $2 ];
|
||||
:local Exit [ :tostr $3 ];
|
||||
|
||||
[ :parse (":log " . $Severity . " \$Message") ];
|
||||
:error ($Severity . ": " . $Message);
|
||||
}
|
||||
|
||||
# log and put (print on terminal) same text
|
||||
:set LogAndPut do={
|
||||
:local Severity [ :tostr $1 ];
|
||||
:local Message [ :tostr $2 ];
|
||||
|
||||
[ :parse (":log " . $Severity . " \$Message") ];
|
||||
:put ($Severity . ": " . $Message);
|
||||
:if ($Severity ~ "^(error|info)\$") do={
|
||||
:if ($Severity = "error" ) do={ :log error $Message; }
|
||||
:if ($Severity = "info" ) do={ :log info $Message; }
|
||||
} else={
|
||||
:log warning $Message;
|
||||
}
|
||||
|
||||
:if ($Exit = "true") do={
|
||||
:error ($Severity . ": " . $Message);
|
||||
} else={
|
||||
:put ($Severity . ": " . $Message);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue