Example #1
0
int CLogBase::EventStr( LOG_GROUP_MASK dwGroupMask, LOGL_TYPE eLogLevel, const LOGCHAR* pszMsg ) // virtual
{
	// override this to route the messages elsewhere
	if ( ! IsLogged( dwGroupMask, eLogLevel ))	// I don't care about these ?
		return( -1 );
	if ( pszMsg == NULL )
		return 0;
	if ( pszMsg[0] == '\0' )
		return 0;
	size_t iLen = lstrlen(pszMsg);
	ASSERT(iLen);
	bool bHasCRLF = ( pszMsg[iLen-1]=='\r' || pszMsg[iLen-1]=='\n' );

	if ( eLogLevel >= LOGL_ERROR )
	{
#ifdef _WINDOWS
		::OutputDebugString( "ERROR:" );
#endif
	}
#ifdef _WINDOWS
	::OutputDebugString( pszMsg );
	if (( dwGroupMask & LOG_GROUP_CRLF ) && ! bHasCRLF )
	{
		::OutputDebugString( LOG_CR );
	}
#else
	// LINUX debug log ?
	UNREFERENCED_PARAMETER(pszMsg);
#endif
	return( 0 );
}
Example #2
0
int CLogBase::VEvent( LOG_GROUP_MASK dwGroupMask, LOGL_TYPE eLogLevel, const LOGCHAR* pszFormat, va_list args ) // virtual
{
	// This is currently not overriden but just in case we might want to.

	if ( ! IsLogged( dwGroupMask, eLogLevel ))	// I don't care about these ?
		return( 0 );

	LOGCHAR szTemp[ 1024 + _MAX_PATH ];	// assume this magic number is big enough. _MAX_PATH
	ASSERT( pszFormat && *pszFormat );
	_vsnprintf( szTemp, sizeof(szTemp)-1, pszFormat, args );

	return( EventStr( dwGroupMask, eLogLevel, szTemp ));
}
Example #3
0
void AccountMgr::LoginAccount(const std::string& userId, const std::string& pw, const std::shared_ptr<Transmission::socket_session>& session){
	auto accout = GetAccount(userId);

	if (accout){
		if (accout->IsLogged())
			AppendReplyBySession(session, LoginRepeatedly);

		if(accout->Login(session, pw) == false)
			AppendReplyBySession(session, LoginFailed_PW);
		else{
			assert(m_pool.find(userId) != m_pool.end());
			m_LoggedAccount[session] = m_pool[userId];
			AppendReplyBySession(session, LoginSucceed);
		}	
	}
	else{
		AppendReplyBySession(session, LoginFailed_AC);
	}
}
Example #4
0
File: CLog.cpp Project: swak/Source
int CLog::EventStr( DWORD wMask, LPCTSTR pszMsg )
{
	// NOTE: This could be called in odd interrupt context so don't use dynamic stuff
	if ( !IsLogged(wMask) )	// I don't care about these.
		return 0;
	else if ( !pszMsg || !*pszMsg )
		return 0;

	int iRet = 0;
	m_mutex.lock();

	try
	{

		// Put up the date/time.
		CGTime datetime = CGTime::GetCurrentTime();	// last real time stamp.

		if ( datetime.GetDaysTotal() != m_dateStamp.GetDaysTotal())
		{
			// it's a new day, open with new day name.
			Close();	// LINUX should alrady be closed.

			OpenLog( NULL );
			Printf( "%s", datetime.Format(NULL));
		}
		else
		{
#ifndef _WIN32
			UINT	mode = OF_READWRITE|OF_TEXT;
			mode |= OF_SHARE_DENY_WRITE;
			Open(NULL, mode);	// LINUX needs to close and re-open for each log line !
#endif
		}

		TCHAR szTime[32];
		sprintf(szTime, "%02d:%02d:", datetime.GetHour(), datetime.GetMinute());
		m_dateStamp = datetime;

		LPCTSTR pszLabel = NULL;

		switch (wMask & 0x07)
		{
			case LOGL_FATAL:	// fatal error !
				pszLabel = "FATAL:";
				break;
			case LOGL_CRIT:	// critical.
				pszLabel = "CRITICAL:";
				break;
			case LOGL_ERROR:	// non-fatal errors.
				pszLabel = "ERROR:";
				break;
			case LOGL_WARN:
				pszLabel = "WARNING:";
				break;
		}
		if ( !pszLabel && ( wMask & LOGM_DEBUG ) && !( wMask & LOGM_INIT ))
			pszLabel = "DEBUG:";

		// Get the script context. (if there is one)
		TCHAR szScriptContext[ _MAX_PATH + 16 ];
		if ( !( wMask&LOGM_NOCONTEXT ) && m_pScriptContext )
		{
			CScriptLineContext LineContext = m_pScriptContext->GetContext();
			sprintf( szScriptContext, "(%s,%d)", m_pScriptContext->GetFileTitle(), LineContext.m_iLineNum );
		}
		else
		{
			szScriptContext[0] = '\0';
		}

		// Print to screen.
		if ( ! ( wMask & LOGM_INIT ) && ! g_Serv.IsLoading())
		{
			SetColor(YELLOW);
			g_Serv.PrintStr( szTime );
			SetColor(DEFAULT);
		}

		if ( pszLabel )	// some sort of error
		{
			SetColor(RED);
			g_Serv.PrintStr( pszLabel );
			SetColor(DEFAULT);
		}

		if ( szScriptContext[0] )
		{
			SetColor(CYAN);
			g_Serv.PrintStr( szScriptContext );
			SetColor(DEFAULT);
		}
		g_Serv.PrintStr( pszMsg );

		// Back to normal color.
		SetColor(DEFAULT);

		// Print to log file.
		WriteString( szTime );
		if ( pszLabel )	WriteString( pszLabel );
		if ( szScriptContext[0] )
		{
			WriteString( szScriptContext );
		}
		WriteString( pszMsg );

		iRet = 1;

#ifndef _WIN32
		Close();
#endif
	}
	catch (...)
	{
		// Not much we can do about this
		iRet = 0;
		CurrentProfileData.Count(PROFILE_STAT_FAULTS, 1);
	}

	m_mutex.unlock();

	return( iRet );
}