⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logger.h

📁 很好用的网络封装库,不熟悉网络编程的人也可以使用。使用风格良好的标准c++编写。
💻 H
📖 第 1 页 / 共 2 页
字号:

	static void setProperty(const std::string& loggerName, const std::string& propertyName, const std::string& value);
		/// Sets or changes a configuration property for all loggers
		/// that are descendants of the Logger with the given name.

	static Logger& get(const std::string& name);
		/// Returns a reference to the Logger with the given name.
		/// If the Logger does not yet exist, it is created, based
		/// on its parent logger.

	static Logger& unsafeGet(const std::string& name);
		/// Returns a reference to the Logger with the given name.
		/// If the Logger does not yet exist, it is created, based
		/// on its parent logger.
		///
		/// WARNING: This method is not thread safe. You should
		/// probably use get() instead.
		/// The only time this method should be used is during
		/// program initialization, when only one thread is running.
		
	static Logger& create(const std::string& name, Channel* pChannel, int level = Message::PRIO_INFORMATION);
		/// Creates and returns a reference to a Logger with the
		/// given name. The Logger's Channel and log level as set as
		/// specified.
		
	static Logger& root();
		/// Returns a reference to the root logger, which is the ultimate
		/// ancestor of all Loggers.
		
	static Logger* has(const std::string& name);
		/// Returns a pointer to the Logger with the given name if it
		/// exists, or a null pointer otherwse.
		
	static void destroy(const std::string& name);
		/// Destroys the logger with the specified name. Does nothing
		/// if the logger is not found.
		///
		/// After a logger has been destroyed, all references to it
		/// become invalid.	
		
	static void shutdown();
		/// Shuts down the logging framework and releases all
		/// Loggers.
		
	static void names(std::vector<std::string>& names);
		/// Fills the given vector with the names
		/// of all currently defined loggers.
		
	static const std::string ROOT; /// The name of the root logger ("").	
		
protected:
	typedef std::map<std::string, Logger*> LoggerMap;

	Logger(const std::string& name, Channel* pChannel, int level);
	~Logger();
	
	void log(const std::string& text, Message::Priority prio);

	static std::string format(const std::string& fmt, int argc, std::string argv[]);
	static void formatDump(std::string& message, const void* buffer, std::size_t length);
	static Logger& parent(const std::string& name);
	static void add(Logger* pLogger);
	static Logger* find(const std::string& name);

private:
	Logger();
	Logger(const Logger&);
	Logger& operator = (const Logger&);
	
	std::string _name;
	Channel*    _pChannel;
	int         _level;

	static LoggerMap* _pLoggerMap;
	static Mutex      _mapMtx;
};


//
// convenience macros
//
#define poco_fatal(logger, msg) \
	if ((logger).fatal()) (logger).fatal(msg) else (void) 0

#define poco_critical(logger, msg) \
	if ((logger).critical()) (logger).critical(msg) else (void) 0

#define poco_error(logger, msg) \
	if ((logger).error()) (logger).error(msg) else (void) 0

#define poco_warning(logger, msg) \
	if ((logger).warning()) (logger).warning(msg) else (void) 0
	
#define poco_notice(logger, msg) \
	if ((logger).notice()) (logger).notice(msg) else (void) 0

#define poco_information(logger, msg) \
	if ((logger).information()) (logger).information(msg) else (void) 0

#if defined(_DEBUG)
	#define poco_debug(logger, msg) \
		if ((logger).debug()) (logger).debug(msg) else (void) 0

	#define poco_trace(logger, msg) \
		if ((logger).trace()) (logger).trace(msg) else (void) 0
#else
	#define poco_debug(logger, msg)
	#define poco_trace(logger, msg)
#endif


//
// inlines
//
inline const std::string& Logger::name() const
{
	return _name;
}


inline int Logger::getLevel() const
{
	return _level;
}


inline void Logger::log(const std::string& text, Message::Priority prio)
{
	if (_level >= prio && _pChannel)
	{
		_pChannel->log(Message(_name, text, prio));
	}
}


inline void Logger::fatal(const std::string& msg)
{
	log(msg, Message::PRIO_FATAL);
}


inline void Logger::critical(const std::string& msg)
{
	log(msg, Message::PRIO_CRITICAL);
}


inline void Logger::error(const std::string& msg)
{
	log(msg, Message::PRIO_ERROR);
}


inline void Logger::warning(const std::string& msg)
{
	log(msg, Message::PRIO_WARNING);
}


inline void Logger::notice(const std::string& msg)
{
	log(msg, Message::PRIO_NOTICE);
}


inline void Logger::information(const std::string& msg)
{
	log(msg, Message::PRIO_INFORMATION);
}


inline void Logger::debug(const std::string& msg)
{
	log(msg, Message::PRIO_DEBUG);
}


inline void Logger::trace(const std::string& msg)
{
	log(msg, Message::PRIO_TRACE);
}


inline bool Logger::is(int level) const
{
	return _level >= level;
}


inline bool Logger::fatal() const
{
	return _level >= Message::PRIO_FATAL;
}


inline bool Logger::critical() const
{
	return _level >= Message::PRIO_CRITICAL;
}


inline bool Logger::error() const
{
	return _level >= Message::PRIO_ERROR;
}


inline bool Logger::warning() const
{
	return _level >= Message::PRIO_WARNING;
}


inline bool Logger::notice() const
{
	return _level >= Message::PRIO_NOTICE;
}


inline bool Logger::information() const
{
	return _level >= Message::PRIO_INFORMATION;
}


inline bool Logger::debug() const
{
	return _level >= Message::PRIO_DEBUG;
}


inline bool Logger::trace() const
{
	return _level >= Message::PRIO_TRACE;
}


} // namespace Poco


#endif // Foundation_Logger_INCLUDED

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -