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

Render Spectre markup in log messages #31

Closed
caesay opened this issue Jan 13, 2024 · 8 comments
Closed

Render Spectre markup in log messages #31

caesay opened this issue Jan 13, 2024 · 8 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@caesay
Copy link

caesay commented Jan 13, 2024

Becuase of this line:

originalFormatString = Markup.Escape(originalFormatString);

It's not possible to pass through Spectre markup in log messages when building rich console applications. It would be nice if this was configurable.

@daningalla
Copy link
Contributor

@caesay - this would not be hard to implement as a configuration, however I feel compelled to discuss. The pure intention of the library is to keep Spectre markup out of logging statements. Can you help me understand the use case of leveraging an abstraction over IAnsiConsole instead of writing directly to it?

@daningalla daningalla added the question Further information is requested label Jan 14, 2024
@caesay
Copy link
Author

caesay commented Jan 14, 2024

I am working on velopack, and all of the core libraries only take a dependency on msft logging, and try to avoid directly using spectre references at all costs, but they do also use spectre markup in the log messages themselves. This feels to me like a good balance, because I can then swap out the logging pipeline to a non-Spectre one without things breaking, and even strip out the markup. Some of the libraries are even intended for use in consuming applications, so having a very high level general abstraction like msft ilogger is important.

I came across this library because there are not many great ways to use Spectre with ILogger. Having tried pretty much everything I can find, most libraries trying to do this are riddled with bugs - and indeed I ran into a few using this project related to using Spectre progress bars in conjunction with logging, so I ended up just writing my own simple Serilog Sink instead - as it seems to solve all the bugs and keeps things really simple.

If you don't think this suggestion would be useful to others, feel free to close this issue.

@daningalla
Copy link
Contributor

I will experiment with adding a property called PreserveOriginalFormatStrings (or similar) in the profile object and see how the tests fare.

Thanks for the input, always appreciated.

@GuillaumeGuerra
Copy link

GuillaumeGuerra commented Mar 22, 2024

Hi 🙌

Thanks a lot for the library, very helpful !!
Indeed, I would appreciate to have an option to support spectre markup out of the box

As said by @caesay, it would be helpful to write formatted logs into the regular ILogger, without applying complex formatting setup, leveraging on the very simple spectre built-in markup language
However, as you said it will generate noise in the other registered loggers, if any, but it's a deployment choice

Thanks again !

@daningalla
Copy link
Contributor

@caesay @GuillaumeGuerra - please see the referenced commit, new dev package will be pushing

@daningalla daningalla added the enhancement New feature or request label Mar 30, 2024
@GuillaumeGuerra
Copy link

will check it out asap

thanks alot ! @daningalla 🙏

@GuillaumeGuerra
Copy link

works like a charm 👍
much appreciated @daningalla !

@daningalla
Copy link
Contributor

Thanks for using @GuillaumeGuerra!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants