How to use properly the logger in a mid-size project #517
Replies: 4 comments 1 reply
-
Hey, yes library is using a singleton and the logger_name is the key. Once you create the Logger you will get the same logger with the recommended way is https://github.com/odygrd/quill/tree/master/examples/recommended_usage you create a wrapper library where you include Backend.h only in the .cpp file. There you handle starting the backend thread. Since the library is header only that will handle compiling all the heavy stuff and you won’t need to include the backend headers anywhere else. after this it’s pretty much your own choice. You can either have an having more than one Logger offers greater control for parts of the application so i would personally create one per different component. This allows to change the log level and have one component on debug log and the other on info for example I prefer the export static Logger* than storing it in each class as it takes additional space eg when you have a in some cases tho it is worth doing it when additional control is needed, or example you have two instances of a class Foo, one instance that is used by component A and one instance used by component B. In that case i would pass logger_a when component A created Foo and logger_b for component B in Foo construction. That way i can see in the log via the logger name which component is actually using Foo and issuing the log and also will be able to have different log levels per component as mentioned above once you set it up also please see how to log different types https://quillcpp.readthedocs.io/en/latest/cheat_sheet.html hope all of this makes sense! If you have any questions let me know |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. I'll implement it and check if new questions arise in the process. I have additional questions: Is changing the log level in runtime possible? how is it evaluated at the log level? As far as I understand there is a log-scale. But I'd like to know more about how this is evaluated. Is there a conditional evaluation (if/switch-case)? How is it optimized for runtime? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
Changing the log_level is per Logger instance It is evaluated with an if statement. If the branch is not taken, then any arguments to the quill/quill/include/quill/LogMacros.h Line 276 in e177e33 if you don’t want the branches you can disable the log level completely in compile time by defining quill/quill/include/quill/LogMacros.h Line 36 in e177e33 |
Beta Was this translation helpful? Give feedback.
-
Hi again, thanks for your answers. I have 2 more additional questions:
Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi. First of all thanks for your amazing work.
Currently, I'm working on a mid-size project. I want to start using this tool. However, I'm still thinking about the best way to use it. I would like to define if I should set up and create an instance of
logger
at main, and inject that instance (probably a shared_prt) in the constructors of my classes. Some of those classes have sub-classes, create other classes' objects, etc. I also have some threads that run constantly and others run on demand.Another option is to use the method
get_logger
. But I am not sure if this library is a singleton, every time that I callget_logger
returns the same original instance.What are your recommendations for a mid-size already deployed project? Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions