snowcone-ltd / libmatoya

Cross-platform application development.
MIT License
578 stars 50 forks source link

Thread-local log disable function #124

Closed Kodikuu closed 3 months ago

Kodikuu commented 11 months ago

Provides MTY_DisableLogThread to allow for disabling logging on a single thread.

Useful if your log callback feeds into a dedicated logging thread (that you don't want recursively logging), or to configure application logging on a per-thread basis.

Currently we try to use MTY_DisableLog for this, but it runs the risk of dropping logging from other threads in the period the logging is disabled.

chrisd1100 commented 9 months ago

I'd prefer to not expand the interface for this purpose. Can we use MTY_DisableLog but give it an int argument, like 0 == off, 1 == global, 2 == thread. Something like that.

Kodikuu commented 9 months ago

I'd prefer to not expand the interface for this purpose. Can we use MTY_DisableLog but give it an int argument, like 0 == off, 1 == global, 2 == thread. Something like that.

That'd probably be fine. I'm off until January, but I'll make that change when I'm back.

I imagine it'd be something like an enum, enum MTY_LogMode

Kodikuu commented 7 months ago

Hmm, this new form only actually works if you're able to drag around your intended global log state everywhere in your application in a thread-safe manner.

Otherwise, some remote thread that wants to momentarily disable it's own logging has no idea what it's supposed to set the global state to. Or any thread that calls the function often may end up setting the wrong state for global logging if it's changed during runtime