edit-icon download-icon


Last Updated: Mar 20, 2018

The client provides a logger by default. If your application has its own logger, we recommend using it, as this facilitates log management.

A logger has the following four elements, as defined in tablestore/util/logger.hpp.

  • Logger interface

    The Logger is used to assemble the contents of a log into a Record object that is forwarded to and written out by the Sinker. The client also organizes the Logger into a tree structure, the root of which is the logger defined by the user in ClientOptions. The request logic and the networking logic use different sub-loggers derived from this root logger.

    1. class Logger
    2. {
    3. public:
    4. enum LogLevel
    5. {
    6. kDebug,
    7. kInfo,
    8. kError,
    9. };
    10. virtual ~Logger() {}
    11. virtual LogLevel level() const =0;
    12. virtual void record(LogLevel, const std::string&) =0;
    13. virtual Logger* spawn(const std::string& key) =0;
    14. virtual Logger* spawn(const std::string& key, LogLevel) =0;
    15. };
    • level() returns the log grade accepted by the Logger. Logs of lower grades are not transferred to the Sinker.
    • record() accepts a log and its grade, and uses them to form a Record object that is sent to the corresponding Sinker of the Logger.
    • spawn() derives a sub-logger.
  • Record interface

    Logger uses the Record object to transfer the contents of the log to the Sinker.

    The Record interface does not provide a method itself. The Logger and Sinker decide which methods the Record class provides.

  • Sinker interface

    Sinker is tasked with writing out Record objects.

    1. class Sinker
    2. {
    3. public:
    4. virtual ~Sinker() {}
    5. virtual void sink(Record*) =0;
    6. virtual void flush() =0;
    7. };
    • sink() writes out a Record. The Record can only be written to a cache.
    • flush() clears the cache to make sure that every log is stored.
  • SinkerCenter singleton object

    SinkerCenter holds all Sinker objects and associates them with certain keys.

    1. class SinkerCenter
    2. {
    3. public:
    4. virtual ~SinkerCenter() {}
    5. static std::tr1::shared_ptr<SinkerCenter> singleton();
    6. virtual Sinker* registerSinker(const std::string& key, Sinker*) =0;
    7. virtual void flushAll() =0;
    8. };
    • singleton() obtains SinkerCenter singleton objects.
    • registerSinker() registers a Sinker in the SinkerCenter.
    • flushAll() clears all Sinkers in the SinkerCenter.
Thank you! We've received your feedback.