Bat: Log syntax highlighting cannot be specified

Created on 26 Oct 2020  路  10Comments  路  Source: sharkdp/bat

I have two files: display-4.log and display-4.log.bak - both of them are python logs with timestamps, optional tags (warning, error) and message

If I do:

  • bat display-4.log, highlight is done okay.
  • bat display-4.log.bak, there is no highlight.
  • bat -llog display-4.log.bak, there is no highlight.
  • bat -l.log display-4.log.bak, I get an error.
  • bat -lsyslog display-4.log.bak (cheating from bat --list-languages), there is still no highlight.

And I ask:

  • What am I doing wrong?
  • Why is bat erroring out on passing file's "theoretical extension" (can it be done?)?
  • Can bat ignore extensions like .bak,.~, etc and invoke it's magical matching after such ignore?
question syntax-highlighting

All 10 comments

Thank you for reporting this. I can not reproduce this.

image

Can you please post the output of the script at https://github.com/sharkdp/bat/blob/master/diagnostics/info.sh in order for us to get more information about your system?

Also, could you please post some content of the log file(s) in question?

I guess the question also is: what are you expecting from the syslog/log highlighting?

Why is bat erroring out on passing file's "theoretical extension" (can it be done?)?

That should actually work. If I understand you correctly. Please post an example that we can use to reproduce

Can bat ignore extensions like .bak,.~, etc and invoke it's magical matching after such ignore?

It can not. But that is an interesting request. I'm not sure if its univerally accepted that whatever.xyz.bak files are actually whatever.xyz files? Or does .bak exist as a separate file extension as well?

Note that you can add something like

--map-syntax '*.log.bak:log'

to bats config file to achieve this for .log.bak files.

Thank you for reporting this. I can not reproduce this.

image

The file format is timestamps, optional tags (warning, error) and message, and not the one you are showing.
It's a bit tricky to post this file, but I'll try to get around it then.

Can you please post the output of the script at https://github.com/sharkdp/bat/blob/master/diagnostics/info.sh in order for us to get more information about your system?

Same goes with anything that I need to exfil from the system in question, but, since we have no other option, I guess I have to.

Also, could you please post some content of the log file(s) in question?

^^

I guess the question also is: what are you expecting from the syslog/log highlighting?

I am expecting that the highlighting would continue working ...

Why is bat erroring out on passing file's "theoretical extension" (can it be done?)?

That should actually work. If I understand you correctly. Please post an example that we can use to reproduce

_Let me add a definition here: "Theoretical extension" is the feature that e.g. formats a file without an extension as a shellscript, because e.g. it contains a shebang (maybe I should've called it file signature? idk)_

... if it's the file's "theoretical extension" that is responsible for its highlight, then I would have expected it to work out of the box (i.e. without -lx) which it didn't do, ...

Note that you can add something like

--map-syntax '*.log.bak:log'

to bats config file to achieve this for .log.bak files.

... and -llog did not work either.

Can bat ignore extensions like .bak,.~, etc and invoke it's magical matching after such ignore?

It can not. But that is an interesting request. I'm not sure if its univerally accepted that whatever.xyz.bak files are actually whatever.xyz files? Or does .bak exist as a separate file extension as well?

Well "universally accepted" I don't know; but that's how I use it, and I haven't seen a file type that ends in .bak

Examples in the wild can be:
https://en.wikipedia.org/wiki/Bak_file
https://file.org/extension/bak
https://filext.com/file-extension/BAK
https://extension.nirsoft.net/bak
https://fileinfo.com/extension/bak

It's a bit tricky to post this file, but I'll try to get around it then.

Ok. Maybe you could try to manually write a minimal example that showcases this bug but does not expose any private information?

Is the content of display-4.log exactly the same as display-4.log.bak? If not, can you try to copy display-4.log.bak to - say - /tmp/display-4.log and try to use bat on that file? Does it work as expected?

It's not about redacting (it's already redacted enough); it's about "moving it out of there and into Github".
I didn't think of it earlier; you can find an example e.g. here https://xpra.org/trac/ticket/2912 (the second code block).

The contents of the files are "similar looking"; .bak is just the rotated version of display-:4.log.

You can attach files to GitHub comments. It would be great to get an actual file to reproduce this. What about the last question in my comment above?

You can attach files to GitHub comments.

Today was a weird day and exfiltrating the files never actually crossed my mind; I'll try for tomorrow.

It would be great to get an actual file to reproduce this.

I think I have meticulously quote-replied to all of your questions. It would be nice if you explicitly quoted which question I have missed.

What about the last question in my comment above?

If your question was exactly the one above:

Is the content of display-4.log exactly the same as display-4.log.bak? If not, can you try to copy display-4.log.bak to - say - /tmp/display-4.log and try to use bat on that file? Does it work as expected?

Then, I have already replied:

I didn't think of it earlier; you can find an example e.g. here xpra.org/trac/ticket/2912 (the second code block).

The contents of the files are "similar looking"; .bak is just the rotated version of display-:4.log.

I was talking about this question:

[鈥 can you try to copy display-4.log.bak to - say - /tmp/display-4.log and try to use bat on that file? Does it work as expected?

You said it's a rotated version of the original. But that could still mean that highlighting fails. Syntax highlighting is not a line-wise process. It can depend on prior lines (think of multiline comments).

Oh, you gave me work for home 馃槄 I missed it.

The problem is the file is not recognized at all, and "I think" it has to do with the extension somehow not invoking "more extended syntax detection features".

I'll try it tomorrow just before uploading.

First of all - the second file extension is .old and not .bak; and renaming does not affect it.

Here are your diagnostics (although not useful I guess):

$ diagnostics/info.sh

system

$ uname -srm
Linux 4.15.0-107-generic x86_64

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.7 LTS
Release: 16.04
Codename: xenial

bat

$ bat --version
bat 0.16.0

$ env

bat_config

$ cat /home/sntentos/.config/bat/config

# Set the theme to "TwoDark"
--theme=OneHalfDark

# Show line numbers, Git modifications, file header and grid
--style="numbers,changes,header,grid"
--style="snip"

# Use italic text on the terminal
--italic-text=always

# Use "gitignore" highlighting for ".ignore" files
--map-syntax .ignore:.gitignore

--pager="/home/sntentos/.installs/smartless/smartless -H"

bat_wrapper

No wrapper script for 'bat'.

bat_wrapper_function

No wrapper function for 'bat'.

No wrapper function for 'cat'.

tool

$ less --version
less 481 (GNU regular expressions)

And here are your files: D.zip

Was this page helpful?
0 / 5 - 0 ratings