Option to output logfile in plain text (even in 256 color xterm terminal)

All your suggestions, requests and ideas for future development
Post Reply
HansCz
Posts: 6
Joined: 27 Jan 2017, 16:00

Option to output logfile in plain text (even in 256 color xterm terminal)

Post by HansCz »

Would it be possible to include an option to force plain text output of the logfile specified with the

Code: Select all

--log-file
option?
It would be desirable, as it would result in more readable logs in less capable terminals and obviate any need for later removal ansicodes if so desired.
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Option to output logfile in plain text (even in 256 color xterm terminal)

Post by rednoah »

256-color output if only enabled if you're using an interactive console, so you won't get color output if you redirect to file or pipe to another process.

Do logs created with --log-file contain color codes? They shouldn't unless you explicitly force that behaviour.


EDIT:

--log-file does indeed print color codes if the command is called with interactive console. A simple workaround would be to just pipe to cat:

Code: Select all

filebot ... | cat
If filebot is called by cron or another process automatically then you won't ever get color codes.
:idea: Please read the FAQ and How to Request Help.
HansCz
Posts: 6
Joined: 27 Jan 2017, 16:00

Re: Option to output logfile in plain text (even in 256 color xterm terminal)

Post by HansCz »

Thanks for the comprehensive answer :)

For some odd reason I assumed that piping and redirecting would also include the ANSI codes. Good design that they don't [thumbs up]

Here's what I end up doing, should anybody want to know:

Code: Select all

$ filebot -script 'fn:amc' [...a lot of options here...]  --log all >>/path/to/log/file.log 2>&1
Note that this will also log anything going to stderr to the log file. In this case it seems to make sense, since I will never run this invocation of filebot in an interactive console.
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Option to output logfile in plain text (even in 256 color xterm terminal)

Post by rednoah »

If filebot is called by a non-interactive shell, it shouldn't be printing color codes in the first place.

However, using 2>&1 has additional benefits and can log errors that the application itself won't be able to log via --log-file due to filebot.sh failing before calling java, the java process itself crashing, logging produced by native code or child processes and so on.
:idea: Please read the FAQ and How to Request Help.
HansCz
Posts: 6
Joined: 27 Jan 2017, 16:00

Re: Option to output logfile in plain text (even in 256 color xterm terminal)

Post by HansCz »

Yes. I was just stupid and assumed during testing in an interactive console, that the ANSI codes would be in the log if filebot were to be called non-interactively. d'oh!
HansCz
Posts: 6
Joined: 27 Jan 2017, 16:00

Re: Option to output logfile in plain text (even in 256 color xterm terminal)

Post by HansCz »

Thank you for an excellent tool, by the way. :)

I ran my first 20 executions or so manually, watching the log, not trusting it to do the right thing.
I was proven wrong. Filebot really just works! (so far :twisted: )
User avatar
rednoah
The Source
Posts: 22994
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Option to output logfile in plain text (even in 256 color xterm terminal)

Post by rednoah »

I wouldn't bet my life on it though. :P

If you have a large number of files, then it's best to deal with them semi-automatically with --mode interactive or at least do a dry-run with --action test first.
:idea: Please read the FAQ and How to Request Help.
Post Reply