gba/common/GBALogger.cpp
changeset 0 164170e6151a
child 5 3b17fc5c9564
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of loggers
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifdef _DEBUG
       
    20 
       
    21 #include    "GBALogger.h"
       
    22 #include    <flogger.h>
       
    23 
       
    24 const TInt KDebugBufferSize1024 = 1024;
       
    25 const TInt KDebugBufferSize240 = 240;
       
    26 const TInt KDebugBufferSize120 = 120;
       
    27 
       
    28 _LIT(KTimeFormat, "%F%D/%M/%Y %J:%T:%S");
       
    29 
       
    30 void debuglineL(const char *a, void *arg1, void* arg1b, void *arg2, void *arg3, const char *arg4) 
       
    31     {
       
    32     
       
    33     HBufC8* logbuf = HBufC8::NewLC( KDebugBufferSize1024 );
       
    34     TPtr8 ptrlogbuf = logbuf->Des();
       
    35     
       
    36     TPtrC8 p((const unsigned char *)a);
       
    37     TPtrC8 temp_arg4((TUint8 *)arg4);
       
    38     ptrlogbuf.Format(p, arg1,arg1b, arg2, arg3);
       
    39     ptrlogbuf.Append(temp_arg4);
       
    40     
       
    41     if ( logbuf->Length() <= KDebugBufferSize120 )
       
    42         {
       
    43         RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
    44                                   EFileLoggingModeAppend, 
       
    45                                   *logbuf );
       
    46         }
       
    47     else
       
    48         {
       
    49         RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
    50                                   EFileLoggingModeAppend, 
       
    51                                   logbuf->Left( KDebugBufferSize120 ) );
       
    52         //max length is 150, print another line 
       
    53         if (logbuf->Mid(KDebugBufferSize120).Length()<= KDebugBufferSize120 )
       
    54             { 
       
    55             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
    56                                       EFileLoggingModeAppend, 
       
    57                                       logbuf->Mid(KDebugBufferSize120) );
       
    58             }
       
    59         else
       
    60             {
       
    61             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
    62                                       EFileLoggingModeAppend, 
       
    63                                       logbuf->Mid(KDebugBufferSize120, KDebugBufferSize120) );
       
    64             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
    65                                       EFileLoggingModeAppend, 
       
    66                                       logbuf->Mid(KDebugBufferSize240) );                           
       
    67             }  
       
    68                                   
       
    69           }     
       
    70     CleanupStack::PopAndDestroy( logbuf );
       
    71     }
       
    72 
       
    73 
       
    74 void debuglineL(const char *a, void *arg1, void* arg1b, void *arg2, void *arg3, const TDesC &arg4) 
       
    75     {
       
    76     
       
    77     HBufC8* logbuf = HBufC8::NewLC( KDebugBufferSize1024 );
       
    78     TPtr8 ptrlogbuf = logbuf->Des();
       
    79     
       
    80     TPtrC8 p((const unsigned char *)a);
       
    81     ptrlogbuf.Format(p, arg1,arg1b, arg2, arg3);
       
    82     ptrlogbuf.Append(arg4);
       
    83     
       
    84     if ( logbuf->Length() <= KDebugBufferSize120 )
       
    85         {
       
    86         RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
    87                                   EFileLoggingModeAppend, 
       
    88                                   *logbuf );
       
    89         }
       
    90     else
       
    91         {
       
    92         RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
    93                                   EFileLoggingModeAppend, 
       
    94                                   logbuf->Left( KDebugBufferSize120 ) );
       
    95         //max length is 150, print another line 
       
    96         if (logbuf->Mid(KDebugBufferSize120).Length()<= KDebugBufferSize120 )
       
    97             { 
       
    98             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
    99                                       EFileLoggingModeAppend, 
       
   100                                       logbuf->Mid(KDebugBufferSize120) );
       
   101             }
       
   102         else
       
   103             {
       
   104             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
   105                                       EFileLoggingModeAppend, 
       
   106                                       logbuf->Mid(KDebugBufferSize120, KDebugBufferSize120) );
       
   107             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
   108                                       EFileLoggingModeAppend, 
       
   109                                       logbuf->Mid(KDebugBufferSize240) );                          	
       
   110             }  
       
   111                                   
       
   112     	  }     
       
   113     CleanupStack::PopAndDestroy( logbuf );
       
   114     }
       
   115 
       
   116 void debuglineL(const char *a, void *arg1, void *arg1b, void *arg2, void *arg3, const TDesC8 &arg4) 
       
   117     {
       
   118     HBufC8* logbuf = HBufC8::NewLC( KDebugBufferSize1024 );
       
   119     TPtr8 ptrlogbuf = logbuf->Des();
       
   120     TPtrC8 p((const unsigned char *)a);
       
   121     ptrlogbuf.Format(p, arg1,arg1b, arg2, arg3);
       
   122     ptrlogbuf.Append(arg4);
       
   123     if ( logbuf->Length() <= KDebugBufferSize120 )
       
   124         {
       
   125         RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
   126                                   EFileLoggingModeAppend, 
       
   127                                   *logbuf );
       
   128         }
       
   129     else
       
   130         {
       
   131         RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
   132                                   EFileLoggingModeAppend, 
       
   133                                   logbuf->Left(KDebugBufferSize120) );
       
   134         //max length is 150, print another line 
       
   135         
       
   136         if (logbuf->Mid(KDebugBufferSize120).Length()<= KDebugBufferSize120 )
       
   137             { 
       
   138             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
   139                                       EFileLoggingModeAppend, 
       
   140                                       logbuf->Mid(KDebugBufferSize120) );
       
   141             }
       
   142         else
       
   143             {
       
   144             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
   145                                       EFileLoggingModeAppend, 
       
   146                                       logbuf->Mid(KDebugBufferSize120, KDebugBufferSize120) );
       
   147             RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
   148                                       EFileLoggingModeAppend, 
       
   149                                       logbuf->Mid(KDebugBufferSize240) );                          	
       
   150             }                               
       
   151     	  }     
       
   152     CleanupStack::PopAndDestroy( logbuf );     
       
   153     }
       
   154 
       
   155 void debuglineL(const char *a, void *arg1, void *arg1b, void *arg2, void *arg3, const char *arg4, const TInt& aNum ) 
       
   156     {
       
   157     HBufC8* logbuf = HBufC8::NewLC( KDebugBufferSize120 );
       
   158     TPtr8 ptrlogbuf = logbuf->Des();
       
   159     TPtrC8 temp_arg4((TUint8 *)arg4);
       
   160     ptrlogbuf.Format( temp_arg4, aNum );
       
   161      
       
   162     debuglineL(a, arg1, arg1b, arg2, arg3, *logbuf);
       
   163     CleanupStack::PopAndDestroy( logbuf );
       
   164     }
       
   165 
       
   166 void debuglineL(const char *a, void *arg1, void *arg1b, void *arg2, void *arg3, const TDesC &arg4, const TInt& aNum ) 
       
   167     {
       
   168     HBufC* logbuf = HBufC::NewLC(KDebugBufferSize120);
       
   169     TPtr ptrlogbuf = logbuf->Des();
       
   170     ptrlogbuf.Format( arg4, aNum );
       
   171     
       
   172     debuglineL(a, arg1, arg1b, arg2, arg3, *logbuf);
       
   173     CleanupStack::PopAndDestroy( logbuf );
       
   174     }    
       
   175 
       
   176 void DebugBinary( const TDesC8 &buf ) 
       
   177     {
       
   178     RFileLogger::HexDump( KGBALogDir, KGBALogFileName,
       
   179         EFileLoggingModeAppend, 
       
   180        NULL, NULL , buf.Ptr(), buf.Length() );
       
   181     } 
       
   182 
       
   183 void debugTTimeL( TTime& aTime )
       
   184     {
       
   185     TBuf<KDebugBufferSize120> buf;
       
   186     aTime.FormatL( buf, KTimeFormat);
       
   187     RFileLogger::WriteFormat( KGBALogDir, KGBALogFileName,
       
   188                              EFileLoggingModeAppend, 
       
   189                              buf );
       
   190     }
       
   191 
       
   192 #endif
       
   193 
       
   194 //EOF