logging: add XLOG() and XLOGF() logging macros
authorAdam Simpkins <simpkins@fb.com>
Thu, 15 Jun 2017 18:03:46 +0000 (11:03 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 15 Jun 2017 18:06:06 +0000 (11:06 -0700)
commit9e55caa86b1d838d9962442255363f37a2ee49fc
treebaf7e04cefc4dbff00caa1e3f1530bff3e6e0ba5
parent1d83c51f9df5c66b3a61048efbbe4ab3d97cf959
logging: add XLOG() and XLOGF() logging macros

Summary:
This adds new `XLOG()` and `XLOGF()` macros to the logging library.  These are
similar to `FB_LOG()` and `FB_LOGF()`, but do not require a Logger argument.
Instead, the log category is picked automatically based on the current file
name.  The basic algorithm for picking the category name is to replace
directory separators with '.', and to strip off the filename extension.

For instance, all `XLOG()` statements in `src/foo/bar.cpp` will log to the
category `src.foo.bar`.  This also works correctly in header files: `XLOG()`
statements in `src/foo/mylib.h` will log to `src.foo.mylib`

This should generally result in a good log category hierarchy without the user
having to spend additional time picking category names--we simply re-use the
decisions that they already made for their directory layout.

In general I expect the `XLOG()` macros to be convenient enough that users will
use `XLOG()` in almost all cases rather than using `FB_LOG()`.

The log category name used by `XLOG()` statements can be overridden using
`XLOG_SET_CATEGORY()`, but this only works in .cpp files, not in header files.

Reviewed By: wez

Differential Revision: D4920257

fbshipit-source-id: 7ffafd9a4c87e6fb5eb35d86e0eb86ef1ed5be95
17 files changed:
CMakeLists.txt
folly/Makefile.am
folly/experimental/logging/LogCategory.cpp
folly/experimental/logging/LogCategory.h
folly/experimental/logging/LogLevel.cpp
folly/experimental/logging/LogLevel.h
folly/experimental/logging/LoggerDB.cpp
folly/experimental/logging/LoggerDB.h
folly/experimental/logging/Makefile.am
folly/experimental/logging/test/LogLevelTest.cpp
folly/experimental/logging/test/XlogFile1.cpp [new file with mode: 0644]
folly/experimental/logging/test/XlogFile2.cpp [new file with mode: 0644]
folly/experimental/logging/test/XlogHeader1.h [new file with mode: 0644]
folly/experimental/logging/test/XlogHeader2.h [new file with mode: 0644]
folly/experimental/logging/test/XlogTest.cpp [new file with mode: 0644]
folly/experimental/logging/xlog.cpp [new file with mode: 0644]
folly/experimental/logging/xlog.h [new file with mode: 0644]