/* * Copyright (c) 2016 The ZLToolKit project authors. All Rights Reserved. * * This file is part of ZLToolKit(https://github.com/ZLMediaKit/ZLToolKit). * * Use of this source code is governed by MIT license that can be found in the * LICENSE file in the root of the source tree. All contributing project authors * may be found in the AUTHORS file in the root of the source tree. */ #include #include "Util/logger.h" #include "Network/Socket.h" using namespace std; using namespace toolkit; class TestLog { public: template TestLog(const T &t){ _ss << t; }; ~TestLog(){}; //通过此友元方法,可以打印自定义数据类型 friend ostream& operator<<(ostream& out,const TestLog& obj){ return out << obj._ss.str(); } private: stringstream _ss; }; int main() { //初始化日志系统 Logger::Instance().add(std::make_shared ()); Logger::Instance().add(std::make_shared()); Logger::Instance().setWriter(std::make_shared()); InfoL << "测试std::cout风格打印:"; //ostream支持的数据类型都支持,可以通过友元的方式打印自定义类型数据 TraceL << "object int"<< TestLog((int)1) << endl; DebugL << "object short:"<