Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python log file (logging) grammar #1402

Closed
vsoch opened this issue Jan 4, 2017 · 14 comments
Closed

Add Python log file (logging) grammar #1402

vsoch opened this issue Jan 4, 2017 · 14 comments
Labels
help welcome Could use help from community

Comments

@vsoch
Copy link
Contributor

vsoch commented Jan 4, 2017

Your library is great! I'm looking to highlight a standard python error log (created with logging), meaning bringing certain lines to the user's attention with a different color. This would be a simple matter of formatting an entire line in one style based on the starting text. For example, here is a log:

https://singularity-hub.org/containers/46/

Right now it looks nice, but the important information (errors, then warnings) doesn't jump out. Ideally, the INFO lines would all be a lighter color, the ERROR would be the most noticable, etc.

I can definitely do the coding for the custom theme, I am hoping you could point me in the right direction of a (close to what I am looking for) language template and /or docs to start? Thanks a bunch!

@shivavelingker
Copy link

Any update on this?

@vsoch
Copy link
Contributor Author

vsoch commented Nov 14, 2018

The maintainer never responded to the issue, so there isn't any update from me :)

@egor-rogov
Copy link
Collaborator

Hi everybody,
the docs are here: https://highlightjs.readthedocs.io/en/latest/
To accomplish the task you'll have to define a new language first, and this is the hard part of it. You can scan through the existing language definitions to find something more or less similar, copy and modify it. Then make sure that all tests pass. Something like this.

@joshgoebel joshgoebel added help welcome Could use help from community new language labels Oct 7, 2019
@joshgoebel joshgoebel changed the title create custom language for error logs based Add Python log file (logging) grammar Oct 7, 2019
@joshgoebel
Copy link
Member

joshgoebel commented Oct 17, 2019

@vsoch Good luck! If you do build a language definition, let us know so we can host it here at highlightjs organization or link people to it so they can find it.

Or if you have any questions about the docs, feel free to ask!


Rather than leave these language request issues open to languish forever (as we have in the past) we're going to start closing them (to clean up the issues list).

I've also moved this request to the wish list (just incase you don't find the time to work on it yourself):
https://github.com/highlightjs/highlight.js/wiki/Grammar-Requests

@vsoch
Copy link
Contributor Author

vsoch commented Oct 17, 2019

I can give a shot at a (very basic) implementation that minimally gets the right levels - I've started on something and I'm having a hard time figuring out how to specify something to be a color - it looks like you can specify class names mentioned here but I'm looking to define a begin/end pattern and then just give it a particular color. Can you point me to docs or an example?

@joshgoebel
Copy link
Member

joshgoebel commented Oct 17, 2019

You aren't in charge of colors, the theme is. You pick the class that best describes what you're trying to do... but honestly for this you only need to decide the class of >>>. The rest of the classes will be coming from using Python as a sublanguage.

I'd use comment perhaps unless you really think it should be highlighted? I think the code is the important part, no?

@joshgoebel
Copy link
Member

Oh sorry I'm thinking of another different thing, lol... still the first part of what I said is accurate... everything you do must fall without one the the established classes.

I mean I suppose you could define your own classes, but they won't be colored by any themes, so that's a bit of a waste.

@vsoch
Copy link
Contributor Author

vsoch commented Oct 17, 2019

Well it’s to define logging output, so you can imagine we’d want reds and oranges for error/warning levels, probably move into purples/blues or green for info, etc. It doesn’t really coincide with how you’d color the syntax. If I’m hearing you correctly there is no way to support this simple use case?

@joshgoebel
Copy link
Member

joshgoebel commented Oct 17, 2019

Nope.

Well you could include your own "recommended" CSS file, but anyone just plugging your extension into the broader library is likely to be using one of the many available themes, not yours. Plus without knowing what theme they are using (light or dark) individual colors would be kind of meaningless. Color only exists in the context of the color around it.

Your CSS file could perhaps include CSS that takes control of the whole <code> block...

.hljs.pythonlog {
}

Though in that case I think you'd want to ship both light and dark themes so someone could pick what most fits with the rest of their site. But at this point your syntax is going to be something very specific that someone chooses to use (and sets up properly including your CSS file, etc)... not just something you could drop into a build with many other languages.

Perhaps a simple use case, but something that hasn't really come up before (AFAIK). :-) Generally we don't want grammars choosing their own colors, so it's a on purpose decision.

Now there is an issue to allow configuring a theme per block, which could be helpful here, but no work has been made on that.

@vsoch
Copy link
Contributor Author

vsoch commented Oct 17, 2019

Hmm, yeah including my own file sounds a bit hacky.

What I could do is pick arbitrary colors (classes) and then minimally the user could select a theme to get variations. It wouldn't be very logical in terms of the color matching, but minimally it would serve to distinguish the levels.

@joshgoebel
Copy link
Member

joshgoebel commented Oct 17, 2019

There is some precedent for shipping separate themes... I've seen at least one of the language repositories do just that...

But yeah for "general" use your options are limited - but might improve if we ever get themes per block... then one could imagine some languages having a "default" theme, though I'm not sure how great an idea that is. Actually I think we'd probably do it the way I already suggested... let people ship "recommended" CSS and then the packagers/users could decide how much CSS they want to include... if they want all the custom CSS or not...

Although still you have the light/dark problem, lol...

@vsoch
Copy link
Contributor Author

vsoch commented Oct 17, 2019

Could you point me to the issue to track the custom styles / theme? I can follow it and upon merge update what I'm working on to use it. In the meantime, I'll see if I can figure out how to contribute a logging theme.

@joshgoebel
Copy link
Member

Well, currently it's just an idea:

#1802

@vsoch
Copy link
Contributor Author

vsoch commented Oct 17, 2019

Thanks! That's exactly what I was looking for - I've subscribed to the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help welcome Could use help from community
Projects
None yet
Development

No branches or pull requests

4 participants