Git Product home page Git Product logo

Comments (5)

tt4g avatar tt4g commented on June 14, 2024 1

For now, the only documentation on custom formatters is the Wiki (the Wiki can be edited by anyone).

If the Wiki documentation lacks information, you are left to figure out how to create a custom formatter from an existing formatter implementation.
See: https://github.com/gabime/spdlog/blob/v1.12.0/include/spdlog/pattern_formatter-inl.h

from spdlog.

tt4g avatar tt4g commented on June 14, 2024

You can use set_color API.

template <typename ConsoleMutex>
SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color(level::level_enum color_level,
string_view_t color) {
std::lock_guard<mutex_t> lock(mutex_);
colors_.at(static_cast<size_t>(color_level)) = to_string_(color);
}

// change the color for the given level
template <typename ConsoleMutex>
void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::set_color(level::level_enum level,
std::uint16_t color) {
std::lock_guard<mutex_t> lock(mutex_);
colors_[static_cast<size_t>(level)] = color;
}

from spdlog.

MPcoreDev avatar MPcoreDev commented on June 14, 2024

Thank you for the reply.
Changing color is not enough for what I want to achieve.

Basically I want the following pattern if the level is below or equal to INFO (the color is only used for the level text):
image

But for other, more critical levels I want:
image

Thus it makes two distinct patterns, with a list of applicable levels for each one.

from spdlog.

tt4g avatar tt4g commented on June 14, 2024

The color range format flag (start: %^, end %$) can be used to adjust the color range of the message, but the ability to set it per log level is not supported.

You may want to consider the custom formatter.

from spdlog.

MPcoreDev avatar MPcoreDev commented on June 14, 2024

Yep I know how to create the pattern. My point was about how to affect pattern to level.
Any doc please about 'custom formatter' I don't manage to find it.
Thanks

from spdlog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.