remotestoragefw/MDebug/src/mdebug.cpp
branchRCL_3
changeset 16 1aa8c82cb4cb
parent 0 3ad9d5175a89
equal deleted inserted replaced
15:88ee4cf65e19 16:1aa8c82cb4cb
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Debug printing to a log file
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <flogger.h>
       
    21 
       
    22 #include "mdebug.h"
       
    23 
       
    24 // FORWARD DECLARATIONS
       
    25 void DoOutput(TDesC8& aData);
       
    26 
       
    27 void DebugStringNarrowL(const char* aFmt, ...)
       
    28     {
       
    29     VA_LIST args;
       
    30     VA_START(args, aFmt);
       
    31     
       
    32     TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt));
       
    33     HBufC8* buf = HBufC8::NewLC(MAX_DEBUG_STRING_LENGTH);
       
    34     buf->Des().FormatList(fmt, args);
       
    35     buf->Des().Append('\n');
       
    36     DoOutput(*buf);
       
    37     CleanupStack::PopAndDestroy(); // buf
       
    38        
       
    39     VA_END(args);
       
    40     }
       
    41 
       
    42 void DebugStringWideL(const char* aFmt, ...)
       
    43     {
       
    44     VA_LIST args;
       
    45     VA_START(args, aFmt);
       
    46     
       
    47     TPtrC8 fmt(reinterpret_cast<const unsigned char *>(aFmt));
       
    48     HBufC* fmt16 = HBufC::NewLC(fmt.Length());
       
    49     fmt16->Des().Copy(fmt);
       
    50     HBufC* buf = HBufC::NewLC(MAX_DEBUG_STRING_LENGTH);
       
    51     buf->Des().FormatList(*fmt16, args);
       
    52     buf->Des().Append('\n');
       
    53     HBufC8* buf8 = HBufC8::NewLC(buf->Length());
       
    54     buf8->Des().Copy(*buf);
       
    55     DoOutput(*buf8);
       
    56     CleanupStack::PopAndDestroy(3); // fmt16, buf, buf8
       
    57 
       
    58     VA_END(args);
       
    59     }
       
    60 
       
    61 void DebugBufferL(const TDesC8& aBuf)
       
    62     {
       
    63     DebugStringNarrowL("\"%S\"", &aBuf);
       
    64     }
       
    65 
       
    66 void DebugBufferL(const TDesC& aBuf)
       
    67     {
       
    68     DebugStringWideL("\"%S\"", &aBuf);
       
    69     }
       
    70 
       
    71 void DebugTimeL(const TTime& aTime)
       
    72     {
       
    73     TBuf<64> dateTimeString;
       
    74     _LIT(KDateString, "%E%D%X%N%Y %1 %2 %3");
       
    75     aTime.FormatL(dateTimeString, KDateString);
       
    76     DebugBufferL(dateTimeString);
       
    77     _LIT(KTimeString, "%-B%:0%J%:1%T%:2%S%.%*C4%:3%+B");
       
    78     aTime.FormatL(dateTimeString, KTimeString);
       
    79     DebugBufferL(dateTimeString);
       
    80     }
       
    81 
       
    82 void DoOutput(TDesC8& aData)
       
    83     {
       
    84     RFileLogger::Write(KDebugDirName,
       
    85                        KDebugFileName,
       
    86                        EFileLoggingModeAppend,
       
    87                        aData);
       
    88     }
       
    89 
       
    90 // End of File