Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document a way to avoid SIOF when extending log4cxx #395

Merged
merged 11 commits into from
Jul 26, 2024
11 changes: 8 additions & 3 deletions src/site/markdown/extending.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ IMPLEMENT_LOG4CXX_OBJECT(NullWriterAppender)
}
~~~

These macros tell Log4cxx what the name of our class is, as well as giving
Log4cxx a way of instansiating our class. Without these macros, the custom
class will not work.
These macros allow Log4cxx to instantiate your class.
The `DECLARE_LOG4CXX_OBJECT` macro adds method declarations and
the `IMPLEMENT_LOG4CXX_OBJECT` macro adds implementations.
The `IMPLEMENT_LOG4CXX_OBJECT` also adds a statically initialized value
that will register your class name with Log4cxx during program startup.
To avoid [Static Initialization Order Fiasco](https://en.cppreference.com/w/cpp/language/siof)
you should place the `IMPLEMENT_LOG4CXX_OBJECT` macro
in the file that loads the configuration.
swebb2066 marked this conversation as resolved.
Show resolved Hide resolved

Now, let's add some basic functionality to our class. As the name of
our class implies, we are going to do nothing with our appender here, as
Expand Down
Loading