#1 2022-11-13 01:07

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Logging

Hi - me again!

In some cases I like to look a little under the hood.

  • Did a special step, pattern or script what it should do?

  • Which decision has been made and why

  • ...

I often find myself switching on and off some rules to read the new names after a preview. This would give a good overview because it will show the names for all marked files.
Additionaly I start this with only some names and extend this.

In most cases it is more elegant to insert a PascalScript-rule at the position to inspect. No need to switch of the later rules ...
For viewing the info I use ShowMessage(FileName). This gives me only informations for one file and pauses the process with each.
Surely this could be finetuned so that the infos are not shown for further files after a press on the cancel button ...

Next step

What I would like to do as a developer is placing log calls in my scripts with severities like WARN, INFO, DEBUG, TRACE or just levels of verbosity.

Local functions or procedures could handle this. Implemented or included. But where should I put the messages. Several ideas:

  1. Collect them in a long string to show them on the last file.
    Actually this would lead in last-file info popups for every rule using this technique.

  2. Writing/appending to a file.
    With propper external tools this could be viewed tail-like.

  3. Send the info to a logging server.
    Idealy this would run locally to be checked whilst in preview mode.
    But how to do this. Are there modules or a dll needed?

  4. Place a (optional) viewing area inside of ReNamer.
    Ok additionally this would need also methods to accept the output. Log level should be adjustable in the view or by script-procedures.
    And if it is already there - the other rules could also log status or other details with a proper log level.

Last edited by jogiwer (2022-11-13 15:19)

Offline

#2 2022-11-15 15:45

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Logging

Got some logging

Just managed to get a log flow over all rules and/or files without disturbing by the use of dialog popups.
Log viewed with LogExpert

Prerequisites

I implemented the two functions proposed by Denis in their Wide variant:

procedure WideSetScriptVar(const Name, Value: WideString);
function WideGetScriptVar(const Name: String): WideString;

With this I could store LogFilename, LogLevel and also the last version of FileName and use them in any rule.

The implementation is not the smartest as it stores the values to the filesystem. But as a proof of concept they do what they should do!

Global value storage and logging have been implemeted in a file which has to be included in your Pascal Script rule.

Usage

As first rule I add a Pascal Script to initialize the logging:

{$INCLUDE Logging.pas}

const
  LOG_FILE = 'C:\Users\xxx\Documents\den4b\ReNamer\Logs\ReNamer-Bilder.log';

var
  Initialized: Boolean;

procedure Init();
begin
  if not Initialized then
  begin
    (* Initialization *)
    LogInit(LOG_FILE, TRACE, [LOG_CLEAR,LOG_HEADER]);

    Initialized := True
  end;
end;

begin
  Init;

  Log(INFO, 'Processing "'+FilePath+'"')
end.

Here I set the loglevel to TRACE and also say that for every run the logfile shall be cleared. The last line puts the full filename of each processed file to the log.

For watching the progress of a single name through the rules I now can insert additional Pascal Script rules with just:

{$INCLUDE Logging.pas}
begin
  LogFileProgress(DEBUG);
end.

More complex implementations in Pascal Script can use their own log statements after including this lib.

Viewing

By now I just use a static filename. With an additional tool like LogExpert I could see the log entries at the time they are written (like the unix tail).

Last edited by jogiwer (2022-11-16 11:47)

Offline

#3 2022-11-15 21:46

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Logging

Informations to log

There could be more information put into the log if they were accessible:

  • A unique id of the ReNamer instance to use a discrete log for every instance

  • Name of the loaded preset

  • Number of the rule the script is running in

  • Maybe the comment of the rule

I read that Pascal might offer further information for the code via the $INCLUDE compiler directive. But they don't work actually. I can't if they should be usable in Pascal Script:

  • {$include %currentRoutine%}

  • {$include %file%}

  • {$include %line%}

Last edited by jogiwer (2022-12-11 14:55)

Offline

#4 2022-12-11 14:25

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Logging

jogiwer wrote:
Informations to log

There could be more information put into the log if they were accessible:

  • A unique id of the ReNamer instance to use a discrete log for every instance

  • Name of the loaded preset

  • Number of the rule the script is running in

  • Maybe the comment of the rule

I read that Pascal might offer further information for the code via the $INCLUDE compiler directive. But they don't work actually. I can't if they should be usable in Pascal Script:

  • {$include %currentRoutine%}

  • {$include %file%}

  • {$include %line%}

Do you think any of this additional information could be provided?

BTW: I'm curious if there isn't someone out there interested in outputs like the one suggested in my screenshot?

Last edited by jogiwer (2022-12-11 14:57)

Offline

#5 2022-12-12 22:59

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Logging

jogiwer wrote:

Do you think any of this additional information could be provided?

{$INCLUDE 'filename.inc'}

This directive includes code from an external file, allowing for easier reuse and better organization of your code.

It can't be used for run-time information that you have requested.

jogiwer wrote:

I'm curious if there isn't someone out there interested in outputs like the one suggested in my screenshot?

A few people have asked for logging capability, but it is usually to have a log of old and new filenames, as processed by ReNamer.

You are the first one to ask for such detailed logging capability.

Offline

#6 2022-12-13 19:38

jogiwer
Member
From: Germany
Registered: 2022-11-05
Posts: 66

Re: Logging

den4b wrote:
{$INCLUDE 'filename.inc'}

This directive includes code from an external file, allowing for easier reuse and better organization of your code.

It can't be used for run-time information that you have requested.

As you can see in my code example I'm using it already that way with {$INCLUDE Logging.pas}.

What I was aiming at was not run-time information but compile-time information as described here. Therefore "currentRoutine", "file" and "line" won't be dynamic any more at the time the script is run.

wiki.freepascal.org wrote:

The compiler can be instructed to insert certain information at a specific spot. For that, a word is surrounded by % like in {$include %internalVariable%}.

But as Pascal Script might have no "compile-time" of that kind and also is only a feature subset this might be out of scope.

A few people have asked for logging capability, but it is usually to have a log of old and new filenames, as processed by ReNamer.

You are the first one to ask for such detailed logging capability.

To be honest my initial demand on logging also was small. Running on pictures taken on several smart phones, cameras and different family members keeps the set of rules growing. And suddenly the phones don't take jpg pictures any more but heic ...

So every now and then there is a situation were the outcome is not as wanted. What I did then (earlier) was to switch off several rules an switch them back on step by step while keeping an eye on the result.

With the need of Pascal Script rules (using exiftool for heic and mov) I found out how to make use of "ShowMessage" - what an improvement compared to the rule-switching.

My NAS is running a syslog-server. Reading another thread about a process bar I just had the idea to send some informations to this server. And for the start I was going to write down some information to a file.

At this time it "exploded" a little. When do I need which information? Ok: let's use loglevels! And to see how the filename changes as many rules as possible should state their changes ...

And last but not least: if every (involved) rule is sending output, how can I tell which rule did this special line.

Offline

Board footer

Powered by FluxBB