[moco-log] Extract LoggingContext class (#6999)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 29 Aug 2019 03:48:35 +0000 (12:48 +0900)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 29 Aug 2019 03:48:35 +0000 (12:48 +0900)
LoggingContext class is currently declared in Log.h, and thus it is
impossible to access this class declaration without including macros
defined in Log.h, which leads to macro name conflicts in some case.

This commit introduce a dedicated file for LoggingContext class to
allow users to access LoggingContext class without the risk of macro
name conflicts.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
compiler/moco-log/include/moco/Log.h
compiler/moco-log/include/moco/LoggingContext.h [new file with mode: 0644]
compiler/moco-log/src/Log.cpp
compiler/moco-log/src/LoggingContext.cpp [new file with mode: 0644]

index 86f2ea3..ec246cd 100644 (file)
@@ -50,16 +50,10 @@ private:
   bool _enabled;
 };
 
-/**
- * @brief Global logging context
- */
-struct LoggingContext
-{
-  static hermes::Context *get(void);
-};
-
 } // namespace moco
 
+#include "moco/LoggingContext.h"
+
 /**
  * HOW TO USE:
  *
diff --git a/compiler/moco-log/include/moco/LoggingContext.h b/compiler/moco-log/include/moco/LoggingContext.h
new file mode 100644 (file)
index 0000000..18f15b1
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __MOCO_LOGGING_CONTEXT_H__
+#define __MOCO_LOGGING_CONTEXT_H__
+
+#include <hermes.h>
+
+namespace moco
+{
+
+/**
+ * @brief Global logging context
+ */
+struct LoggingContext
+{
+  static hermes::Context *get(void);
+};
+
+} // namespace moco
+
+#endif // __MOCO_LOGGING_CONTEXT_H__
index 8d6974b..4d204ee 100644 (file)
@@ -16,9 +16,6 @@
 
 #include "moco/Log.h"
 
-#include <hermes/ConsoleReporter.h>
-#include <stdex/Memory.h>
-
 #include <cassert>
 #include <cstdlib>
 #include <iostream>
@@ -88,25 +85,3 @@ void LoggerConfig::configure(const Logger *, hermes::Source::Setting &setting) c
 }
 
 } // namespace moco
-
-//
-// LoggingContext
-//
-namespace moco
-{
-
-hermes::Context *LoggingContext::get(void)
-{
-  static hermes::Context *ctx = nullptr;
-
-  if (ctx == nullptr)
-  {
-    ctx = new hermes::Context;
-    ctx->sinks()->append(stdex::make_unique<hermes::ConsoleReporter>());
-    ctx->config(stdex::make_unique<LoggerConfig>());
-  }
-
-  return ctx;
-}
-
-} // namespace moco
diff --git a/compiler/moco-log/src/LoggingContext.cpp b/compiler/moco-log/src/LoggingContext.cpp
new file mode 100644 (file)
index 0000000..a004e1d
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "moco/LoggingContext.h"
+#include "moco/Log.h"
+
+#include <hermes/ConsoleReporter.h>
+#include <stdex/Memory.h>
+
+namespace moco
+{
+
+hermes::Context *LoggingContext::get(void)
+{
+  static hermes::Context *ctx = nullptr;
+
+  if (ctx == nullptr)
+  {
+    ctx = new hermes::Context;
+    ctx->sinks()->append(stdex::make_unique<hermes::ConsoleReporter>());
+    ctx->config(stdex::make_unique<LoggerConfig>());
+  }
+
+  return ctx;
+}
+
+} // namespace moco