OLD | NEW |
(Empty) | |
| 1 // Copyright (C) 2011 Google Inc. |
| 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 // Author: Philippe Liard |
| 16 |
| 17 #ifndef I18N_PHONENUMBERS_LOGGER_H_ |
| 18 #define I18N_PHONENUMBERS_LOGGER_H_ |
| 19 |
| 20 #include <cstdio> |
| 21 #include <string> |
| 22 |
| 23 #include "base/memory/scoped_ptr.h" |
| 24 |
| 25 namespace i18n { |
| 26 namespace phonenumbers { |
| 27 |
| 28 using std::string; |
| 29 |
| 30 enum LogLevel { |
| 31 LOG_FATAL = 1, |
| 32 LOG_ERROR, |
| 33 LOG_WARNING, |
| 34 LOG_INFO, |
| 35 LOG_DEBUG, |
| 36 }; |
| 37 |
| 38 enum { |
| 39 DFATAL = LOG_FATAL, |
| 40 // ERROR seems to be defined on MSVC, therefore don't overwrite it. |
| 41 #ifndef ERROR |
| 42 ERROR = LOG_ERROR, |
| 43 #endif |
| 44 WARNING = LOG_WARNING, |
| 45 }; |
| 46 |
| 47 // Subclass this abstract class to override the way logging is handled in the |
| 48 // library. You can then call the PhoneNumberUtil::SetLogger() method. |
| 49 class Logger { |
| 50 public: |
| 51 Logger() : level_(LOG_ERROR) {} |
| 52 virtual ~Logger() {} |
| 53 |
| 54 // Writes the message level to the underlying output stream. |
| 55 virtual void WriteLevel() {} |
| 56 // Writes the provided message to the underlying output stream. |
| 57 virtual void WriteMessage(const string& msg) = 0; |
| 58 |
| 59 inline LogLevel level() const { |
| 60 return level_; |
| 61 } |
| 62 |
| 63 inline void set_level(LogLevel level) { |
| 64 level_ = level; |
| 65 } |
| 66 |
| 67 static inline void set_logger_impl(Logger* logger) { |
| 68 impl_ = logger; |
| 69 } |
| 70 |
| 71 static inline Logger* mutable_logger_impl() { |
| 72 return impl_; |
| 73 } |
| 74 |
| 75 private: |
| 76 static Logger* impl_; |
| 77 LogLevel level_; |
| 78 }; |
| 79 |
| 80 // Logger that does not log anything. It could be useful to "mute" the |
| 81 // phonenumber library. |
| 82 class NullLogger : public Logger { |
| 83 public: |
| 84 virtual ~NullLogger() {} |
| 85 |
| 86 virtual void WriteMessage(const string& /* msg */) {} |
| 87 }; |
| 88 |
| 89 } // namespace phonenumbers |
| 90 } // namespace i18n |
| 91 |
| 92 #endif // I18N_PHONENUMBERS_LOGGER_ADAPTER_H_ |
OLD | NEW |