• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CONTRIB_S3_S3_LOGGING_H_
17 #define TENSORFLOW_CONTRIB_S3_S3_LOGGING_H_
18 
19 #include <atomic>
20 #include <string>
21 
22 #include <aws/core/utils/logging/LogLevel.h>
23 #include <aws/core/utils/logging/LogSystemInterface.h>
24 #include "tensorflow/core/platform/default/logging.h"
25 
26 namespace tensorflow {
27 
28 class AWSLogSystem : public Aws::Utils::Logging::LogSystemInterface {
29  public:
30   static void InitializeAWSLogging();
31   static void ShutdownAWSLogging();
32 
33   explicit AWSLogSystem(Aws::Utils::Logging::LogLevel log_level);
34   virtual ~AWSLogSystem() = default;
35 
36   // Gets the currently configured log level.
GetLogLevel(void)37   virtual Aws::Utils::Logging::LogLevel GetLogLevel(void) const override {
38     return log_level_;
39   }
40 
41   // Set a new log level. This has the immediate effect of changing the log.
SetLogLevel(Aws::Utils::Logging::LogLevel log_level)42   void SetLogLevel(Aws::Utils::Logging::LogLevel log_level) {
43     log_level_.store(log_level);
44   }
45 
46   // Does a printf style output to ProcessFormattedStatement. Don't use this,
47   // it's unsafe. See LogStream.
48   // Since non-static C++ methods have an implicit this argument,
49   // TF_PRINTF_ATTRIBUTE should be counted from two (vs. one).
50   virtual void Log(Aws::Utils::Logging::LogLevel log_level, const char* tag,
51                    const char* format, ...) override TF_PRINTF_ATTRIBUTE(4, 5);
52 
53   // Writes the stream to ProcessFormattedStatement.
54   virtual void LogStream(Aws::Utils::Logging::LogLevel log_level,
55                          const char* tag,
56                          const Aws::OStringStream& messageStream) override;
57 
58  private:
59   void LogMessage(Aws::Utils::Logging::LogLevel log_level,
60                   const string& message);
61   std::atomic<Aws::Utils::Logging::LogLevel> log_level_;
62 
63   TF_DISALLOW_COPY_AND_ASSIGN(AWSLogSystem);
64 };
65 
66 }  // namespace tensorflow
67 
68 #endif  // TENSORFLOW_CONTRIB_S3_S3_LOGGING_H_
69