natfw/natfwunsaf_protocols/natfwunsafshared/inc/natfwunsaflog.inl
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-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:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32svr.h>
       
    23 #include <utf.h>
       
    24 
       
    25 //To direct logs to RFileLogger, define the following flag
       
    26 #undef WRITE_LOGS_TO_FILE
       
    27 
       
    28 #if defined( WRITE_LOGS_TO_FILE )
       
    29 
       
    30 #include <flogger.h>
       
    31 
       
    32 //Write logs to /c/logs/natfw/unsaflog.txt
       
    33 _LIT(KLogFileDir, "natfw");
       
    34 _LIT(KLogFileName, "unsaflog.txt");
       
    35 
       
    36 #define DO_WRITE(s)     RFileLogger::Write(KLogFileDir, KLogFileName, \
       
    37 EFileLoggingModeAppend, (s))
       
    38 
       
    39 #else
       
    40 
       
    41 #define DO_WRITE(s)        RDebug::RawPrint(s)
       
    42 
       
    43 #endif
       
    44 
       
    45 
       
    46 inline void NATFWUNSAFLog::Print(
       
    47     const TDesC16& aStr)
       
    48     {
       
    49     _LIT(KLogFormat, "NATFW/UNSAF Protocols: %S");
       
    50     TBuf<256> str;
       
    51     str.Format(KLogFormat, &aStr);
       
    52     str.Append('\n');
       
    53     DO_WRITE(str);
       
    54     }
       
    55 
       
    56 inline void NATFWUNSAFLog::Print(
       
    57     const TDesC16& aStr1,
       
    58     const TDesC8& aStr2)
       
    59     {
       
    60     _LIT(KLogFormat, "NATFW/UNSAF Protocols: %S: %S");
       
    61     TBuf<100> str2;
       
    62     CnvUtfConverter::ConvertToUnicodeFromUtf8(str2, aStr2);
       
    63     TBuf<256> str;
       
    64     str.Format(KLogFormat, &aStr1, &str2);
       
    65     str.Append('\n');
       
    66     DO_WRITE(str);
       
    67     }
       
    68 
       
    69 inline void NATFWUNSAFLog::Print(
       
    70     const TDesC16& aStr1,
       
    71     const TDesC16& aStr2)
       
    72     {
       
    73     _LIT(KLogFormat, "NATFW/UNSAF Protocols: %S: %S");
       
    74     TBuf<256> str;
       
    75     str.Format(KLogFormat, &aStr1, &aStr2);
       
    76     str.Append('\n');
       
    77     DO_WRITE(str);
       
    78     }
       
    79 
       
    80 inline void NATFWUNSAFLog::Print(
       
    81     const TDesC16& aStr,
       
    82     TInt aValue)
       
    83     {
       
    84     _LIT(KLogFormat, "NATFW/UNSAF Protocols: %S: %d");
       
    85     TBuf<256> str;
       
    86     str.Format(KLogFormat, &aStr, aValue);
       
    87     str.Append('\n');
       
    88     DO_WRITE(str);
       
    89     }
       
    90 
       
    91 inline void NATFWUNSAFLog::Print(
       
    92     const TDesC16& aStr,
       
    93     const TInetAddr& aAddr)
       
    94     {
       
    95     _LIT(KLogFormat, "NATFW/UNSAF Protocols: %S: %S port %d");
       
    96     const TInt KIPv6AddrMaxLen = 39;
       
    97     TBuf<KIPv6AddrMaxLen> addrBuf;
       
    98     aAddr.Output(addrBuf);
       
    99     TBuf<256> str;
       
   100     str.Format(KLogFormat, &aStr, &addrBuf, aAddr.Port());
       
   101     str.Append('\n');
       
   102     DO_WRITE(str);
       
   103     }
       
   104 
       
   105 inline void NATFWUNSAFLog::PrintByteStream(
       
   106     const TDesC16& aStr1,
       
   107     const TDesC8& aStr2)
       
   108     {
       
   109     _LIT(KLogFormat, "NATFW/UNSAF Protocols: %S:" );
       
   110 
       
   111     const TInt KLengthOfByte = 3;
       
   112     const TInt KMaxLineLength = 100;
       
   113     TBuf< KMaxLineLength > logBuf;
       
   114 
       
   115     logBuf.Format( KLogFormat, &aStr1 );
       
   116     DO_WRITE( logBuf );
       
   117 
       
   118     TInt inputPos = 0;
       
   119     while ( inputPos < aStr2.Length() )
       
   120         {
       
   121         logBuf.Zero();
       
   122 
       
   123         TInt outputPos = 0;
       
   124         while ( ( outputPos < KMaxLineLength - KLengthOfByte ) &&
       
   125                 ( inputPos < aStr2.Length() ) )
       
   126             {
       
   127             logBuf.AppendFormat( _L( "%02x " ), aStr2[ inputPos++ ] );
       
   128             outputPos += KLengthOfByte;
       
   129             }
       
   130         logBuf.Append('\n');
       
   131         DO_WRITE( logBuf );
       
   132         }
       
   133     }