Example #1
0
BOOL Log_App_FileWrite( char *filename, char *txt )
{
	if( CFG->cfgEnableLogs )
	{
		CFile localFile;
		BOOL result;

		result = localFile.Open( filename, CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate );

		if( !result )
		{
			CreateDirectory( "Logs" , NULL );
			result = localFile.Open( filename, CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate );
		}

		if( result && txt )
		{
			long filesize = localFile.GetLength();
			localFile.SeekToEnd();
			localFile.Write( txt, strlen(txt) );
			localFile.Write( "\r\n", 2 );
			localFile.Close();
			if( filesize > 1024*1024 )
			{
				RollLogFile( filename );
			}
			return TRUE;
		}
		else
			return FALSE;
	} else
		OutputDebugString( txt );
	return FALSE;
}
Example #2
0
void SymbianLog::printMessage(const char* level, const char* msg, PLATFORM_VA_LIST argList) 
{
    iSemaphore.Wait();
    
    StringBuffer currentTime = createCurrentTime(true);
    
    TInt err = file.Open(fsSession, iLogName, EFileWrite|EFileShareAny);
    TInt pos = 0;
    
    if (err == KErrNotFound) 
    {
        // First time: file does not exist. Create it.
        err = file.Create(fsSession, iLogName, EFileWrite|EFileShareAny);
        if (err != KErrNone) {
            setErrorF(err, "SymbianLog: could not open log file (code %d)", err);
            goto finally;
        }
        StringBuffer header = createHeader();
        RBuf8 data;
        data.Assign(stringBufferToNewBuf8(header));
        file.Write(data);
        data.Close();
    }
    else 
    {
        err = file.Seek(ESeekEnd, pos);
        if (err != KErrNone) {
            setErrorF(err, "SymbianLog: seek error on log file (code %d)", err);
            goto finally;
        }
    }

    {
        // Write the data
        StringBuffer line, data;
        line.sprintf("%s -%s- %s", currentTime.c_str(), level, msg);
        data.vsprintf(line.c_str(), argList);
        data.append("\n");
        
        RBuf8 buf;
        buf.Assign(stringBufferToNewBuf8(data));
        file.Write(buf);
        buf.Close();
    }
    
finally:
    file.Close();
    // we need closed file to operate on it
    if ( LogSize() > SYMBIAN_LOG_SIZE ){
        // roll log file
        RollLogFile();
    }
    iSemaphore.Signal();
}