Ejemplo n.º 1
0
//-------------------------------------------------------------------------------------------------
Logger *Configuration::create_logger(const XmlElement *from, const Logtype ltype, const SessionID *sid) const
{
	string name;
	if (from && from->GetAttr(ltype == session_log ? "session_log" : "protocol_log", name))
	{
		const XmlElement *which(find_logger(name));
		if (which)
		{
			string type;
			if (which->GetAttr("type", type)
				&& ((type % "session" && ltype == session_log) || (type % "protocol" && ltype == protocol_log)))
			{
				string logname("logname_not_set.log");
				which->FindAttrRef("filename", logname);
				trim(logname);

				if (logname[0] == '|')
#ifndef HAVE_POPEN
					throw f8Exception("popen not supported on your platform");
#endif
					return new PipeLogger(logname, get_logflags(which));

				RegMatch match;
				if (_ipexp.SearchString(match, logname, 3) == 3)
				{
					f8String ip, port;
					_ipexp.SubExpr(match, logname, ip, 0, 1);
					_ipexp.SubExpr(match, logname, port, 0, 2);
					BCLogger *bcl(new BCLogger(ip, get_value<unsigned>(port), get_logflags(which)));
					if (*bcl)
						return bcl;
				}

				get_logname(which, logname, sid); // only applies to file loggers
				return new FileLogger(logname, get_logflags(which), get_logfile_rotation(which));
			}
		}
	}

	return 0;
}
Ejemplo n.º 2
0
//-------------------------------------------------------------------------------------------------
Logger *Configuration::create_logger(const XmlEntity *from, const Logtype ltype) const
{
	string name;
	if (from && from->GetAttr(ltype == session_log ? "session_log" : "protocol_log", name))
	{
		const XmlEntity *which(find_logger(name));
		if (which)
		{
			string type;
			if (which->GetAttr("type", type)
				&& ((type % "session" && ltype == session_log) || (type % "protocol" && ltype == protocol_log)))
			{
				string logname("logname_not_set.log");
				trim(get_logname(which, logname));

				if (logname[0] == '|' || logname[0] == '!')
					return new PipeLogger(logname, get_logflags(which));

				RegMatch match;
				if (_ipexp.SearchString(match, logname, 3) == 3)
				{
					f8String ip, port;
					_ipexp.SubExpr(match, logname, ip, 0, 1);
					_ipexp.SubExpr(match, logname, port, 0, 2);
					BCLogger *bcl(new BCLogger(ip, GetValue<unsigned>(port), get_logflags(which)));
					if (*bcl)
						return bcl;
				}

				return new FileLogger(logname, get_logflags(which), get_logfile_rotation(which));
			}
		}
	}

	return 0;
}