|
@@ -5,10 +5,13 @@
|
|
|
// Created by Sam Jaffe on 4/13/19.
|
|
// Created by Sam Jaffe on 4/13/19.
|
|
|
//
|
|
//
|
|
|
|
|
|
|
|
|
|
+#include <thread>
|
|
|
|
|
+
|
|
|
#include <gmock/gmock.h>
|
|
#include <gmock/gmock.h>
|
|
|
|
|
|
|
|
#include "resource_factory/prototype_factory.hpp"
|
|
#include "resource_factory/prototype_factory.hpp"
|
|
|
|
|
|
|
|
|
|
+#include "logger/detail/data_accessors.h"
|
|
|
#include "logger/detail/layout.h"
|
|
#include "logger/detail/layout.h"
|
|
|
#include "logger/exception.h"
|
|
#include "logger/exception.h"
|
|
|
#include "logger/log_manager.h"
|
|
#include "logger/log_manager.h"
|
|
@@ -257,6 +260,30 @@ TEST(PatternLayoutTest, CanOutputLocation) {
|
|
|
EXPECT_THAT(message, testing::MatchesRegex(regex));
|
|
EXPECT_THAT(message, testing::MatchesRegex(regex));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+TEST(PatternLayoutTest, CanOutputThreadInfoAsThreadId) {
|
|
|
|
|
+ using testing::Eq;
|
|
|
|
|
+ std::stringstream ss;
|
|
|
|
|
+ ss << std::this_thread::get_id();
|
|
|
|
|
+ EXPECT_THAT(DoFormat("%t", getpkt("")), Eq(ss.str()));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(PatternLayoutTest, OutputsThreadNameIfAvailable) {
|
|
|
|
|
+ using testing::Eq;
|
|
|
|
|
+ ::logging::detail::thread_info_helper::set_name("main");
|
|
|
|
|
+ EXPECT_THAT(DoFormat("%t", getpkt("")), Eq("main"));
|
|
|
|
|
+ ::logging::detail::thread_info_helper::set_name("");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+TEST(PatternLayoutTest, ThreadNameIsThreadLocalStorage) {
|
|
|
|
|
+ using testing::Ne;
|
|
|
|
|
+ ::logging::detail::thread_info_helper::set_name("main");
|
|
|
|
|
+ std::thread tr([](){
|
|
|
|
|
+ EXPECT_THAT(DoFormat("%t", getpkt("")), Ne("main"));
|
|
|
|
|
+ });
|
|
|
|
|
+ tr.join();
|
|
|
|
|
+ ::logging::detail::thread_info_helper::set_name("");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
TEST(PatternLayoutTest, ThrowsOnUnknownToken) {
|
|
TEST(PatternLayoutTest, ThrowsOnUnknownToken) {
|
|
|
using testing::Eq;
|
|
using testing::Eq;
|
|
|
EXPECT_THROW(GetPatternLayout("%q"),
|
|
EXPECT_THROW(GetPatternLayout("%q"),
|