Skip to content

This repository contains an implementation example of an abstract logger in a C++ library

License

Notifications You must be signed in to change notification settings

legerch/AbstractLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository contains an implementation example of an abstract logger in a C++ library.

Table of contents :

1. Requirements

1.1. C++ Standards

Implementation example requires at least C++ 11 standard

1.2. Dependencies

No dependencies needed

2. How to use

This repository contains an example of an Abstract logger that can be useful when developping a library. This allow to not be tied to a specific log dependency/api, allowing users to choose their own (spdlog, glog, etc...).

Tip

If needed, a library template repository also exist to help for the library creation

2.1. Usage inside library

Abstract Logger behaviour can be found inside folder lib/logs, some tweaks are needed and directly dependant to developped library:

  • Set proper namespace in all 3 classes(in our example, libra is the name of our library)
  • Set log macros names (replace #define LIBRA_LOG_FATAL(msg) by YOURLIBNAME_LOG_FATAL(msg))

That is all, now to you use log, caller just need to call proper macro (example can be found inside mock class Person).

Tip

For easier integration, a single pair header/source exists at lib/logs_single_file folder

2.2. Set logger for users of the library

By default, no logs will be printed or written, users of library must explicitly define a class which inherit from ILogger class.
This repository provide some examples of ILogger subclasses inside example/sinks:

  • Logger Qt: subclass implementation to be compatible with Qt logging behaviour

Once a sink class has been implemented, we simply have to register this sink for the library via:

int main(int argc, char *argv[])
{
    /* Set logs */
    MyCustomSink libSink;
    libra::LogManager::setLogger(&libSink);

    /* Then proceed to the other "main" tasks */
}

Tip

Example can be found inside example/main.cpp file

3. Documentation

All methods has been documented with Doxygen utility, documentation can be generated by using:

# Run documentation generation
doxygen ./Doxyfile

# Under Windows OS, maybe doxygen is not added to the $PATH
"C:\Program Files\doxygen\bin\doxygen.exe" ./Doxyfile

Note: You can also load the Doxyfile into Doxywizard (Doxygen GUI) and run generation.

4. License

This library is licensed under MIT license.

About

This repository contains an implementation example of an abstract logger in a C++ library

Resources

License

Stars

Watchers

Forks

Packages

No packages published