executeScript and logging

Running FileBot from the console, Groovy scripting, shell scripts, etc
Post Reply
Zalon
Posts: 2
Joined: 05 Nov 2013, 16:34

executeScript and logging

Post by Zalon »

Hello

First off, thanks for making such an awesome program! I've been working on automating my media workflow using filebot and it's groovy scripts, I've made a lot of small custom scripts and now I would like to combine them in a postproccesing script.

In my scripts I use different logging levels and then I save the info level to individual log files. This works great when running the scripts from the command line like this:

Code: Select all

filebot -script scripts/script.groovy --log info --log-file script.log
My plan was to just run all the scripts using a linux bash script, but then I figured that it would be nicer with a cross-platform approach, using groovy. Looking at the functionality available, I've found the execute and the executeScript functions. It's easy to do what I want using the execute function, as I can then just launch a new instance of filebot with a given script and a defined logfile. However, filebot takes quite some time to initialize when launched, so launching a new instance for each script will delay the process a lot.

Using the executeScript function I can run the script and pass arguments and variables to it, without launching a new instance of filebot, but I would like to be able to log the output from each script to it's own log file.

My question, is it possible to define the loglevel and the logfile within a script, so I could somehow change it before executing each of the sub-scripts?
User avatar
rednoah
The Source
Posts: 23938
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: executeScript and logging

Post by rednoah »

My scripting system doesn't allow that since IO gets redirected in the core on startup.

But I can't stop you from setting System.out and System.err during the script:
http://docs.oracle.com/javase/7/docs/ap ... tStream%29

So just set stdout/stderr to different files before the executeScript calls.



If you wanna pipe things to file as well as stdout you can use my net.sourceforge.tuned.TeePrintStream:

Code: Select all

// out is some FileOutputStream
System.setOut(new TeePrintStream(out, true, "UTF-8", System.out));
:idea: Please read the FAQ and How to Request Help.
Zalon
Posts: 2
Joined: 05 Nov 2013, 16:34

Re: executeScript and logging

Post by Zalon »

Thanks for your answer, I got it working now :D

For future reference, this is how I ended up doing it:

Code: Select all

import net.sourceforge.tuned.TeePrintStream

// Open log file
scriptlog = new FileOutputStream(new File("logfile.log"),true)

// Stream output to log file
System.setOut(new TeePrintStream(scriptlog, true, "UTF-8", System.out));

// Execute script
executeScript('test', [login:"username", addshows:true], "arg1", "arg2", "arg3")

// Close log file
scriptlog.close();
User avatar
rednoah
The Source
Posts: 23938
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: executeScript and logging

Post by rednoah »

Keep in mind that if you wanna do this multiple times you have to remember the original System.out before you start setting it for the different executeScript calls.
:idea: Please read the FAQ and How to Request Help.
Post Reply