Example #1
0
void LogManager::setLogLevel(const char* tag, LogLevel level)
{
	_mutex.lock();

	LogTagID tagID = tagId(tag);
	Tags::iterator itr = _tags.find(tagID);

	// if no such tag yet, register it
	if (itr == _tags.end())
	{
		LogTagInfo ti;
		ti.level = level;
		_tags.insert(std::make_pair(tagID, ti));
	}
	else
	{
		// specify log level to the tag
		itr->second.level = level;
	}

	_mutex.unlock();
}
Example #2
0
    void CiffComponent::print(std::ostream& os,
                             ByteOrder byteOrder,
                             const std::string& prefix) const
    {
        os << prefix
           << "tag = 0x" << std::setw(4) << std::setfill('0')
           << std::hex << std::right << tagId()
           << ", dir = 0x" << std::setw(4) << std::setfill('0')
           << std::hex << std::right << dir()
           << ", type = " << TypeInfo::typeName(typeId())
           << ", size = " << std::dec << size_
           << ", offset = " << offset_ << "\n";

        Value::AutoPtr value;
        if (typeId() != directory) {
            value = Value::create(typeId());
            value->read(pData_, size_, byteOrder);
            if (value->size() < 100) {
                os << prefix << *value << "\n";
            }
        }
    } // CiffComponent::print
Example #3
0
void LogManager::doLog(LogChannel* channel, const char* act, const char* srcname, uint line, const char* fnname, const char* tag, const char* msg, int msgLen, bool forceLineEnd)
{
	if (_shutdown) return;

	if (channel == NULL)
		channel = needThreadRootChannel();

	Mutex::ScopedLock lock(channel->_mutex);

	if (msgLen < 0)
		msgLen = strlen(msg);

	assert(channel);

	LogEntry e;
	e.time = float(SystemTimer::now());
	e.channel = channel;
	e.srcName = srcname;
	e.line = line;
	e.fnName = fnname;
	e.act = act;

	uint32 tagbuf = 0;

	if (tag == NULL)
		tag = parseTag(msg, msgLen, tagbuf);

	if (*tag == 0)
	{
		// no tag detected: use previous tag
		tagbuf = channel->_prevTag;
		tag = reinterpret_cast<const char*>(&tagbuf);
	}
	else
	{
		// TODO: MT-Safe
		strcpy(reinterpret_cast<char*>(&channel->_prevTag), tag);
	}

	e.tagStr = tag;
	e.tagID = tagId(tag);
	e.logLevel = getLogLevel(e.tagID);


	const char* lineStart = msg;
	const char* lineEnd = msg;
	const char* msgEnd = msg + msgLen;
	const char* ch = msg;

	while (true)
	{
		if (ch < msgEnd && *ch != '\n')
		{
			++ch;
			continue;
		}

		lineEnd = ch;

		e.lineEnd = *ch == '\n' || forceLineEnd;
		e.message = lineStart;
		e.messageLen = lineEnd - lineStart;

		doLog(&e);

		if (ch >= msgEnd) break;

		e.srcName = NULL;
		e.line = 0;
		e.fnName = NULL;

		lineStart = ++ch;
		if (ch >= msgEnd) break;
	}
}