Skip to content

Getting Started

Filip Dutescu edited this page Mar 10, 2020 · 6 revisions

Getting Started

This section will provide the information needed to include SBLogger in your projects, either as source code or as a library.

Note: From now on, I will refer to this library as SBLogger.

Prerequisites

This library was developed using C++17 and thus you will have the best experience using a C++17 (or later) compiler. For compilers pre C++17 (C++11 or C++14) or post C++17 (as of this writing, C++20), please refer to Setting Up.

Including in Your Projects

All you need to do if you wish to use SBLogger (in a C++ project) is to clone/fork the repo or download the SmallBetterLogger.hpp file to your project and add it as a header file in your code:

...
#include "SmallBetterLogger.hpp"
...

Logging Your First Message

After including the library and defining the required macros/settings, as shown above, to start logging messages all you need to do is create an instance of a logger. All loggers are found in the sblogger namespace.

Here are some quick examples of how to log messages:

Note: More information can be found in the Logging Messages page and more examples in the Usage Examples page.

1. Logging in standard streams (STDOUT, STDERR or STDLOG):

...
#include "SmallBetterLogger.hpp"
...
sblogger::StreamLogger logger;
...
logger.WriteLine("Hello World!");
...

Output:

Hello World!

2. Logging in files:

...
#include "SmallBetterLogger.hpp"
...
sblogger::FileLogger logger("my.log");
...
logger.WriteLine("Hello");
logger.Write("{0}!", "World");
...

Output:

#In "my.log"
Hello
World!