browserutilities/downloadmgr/DownloadMgrUiLib/Inc/UiLibLogger.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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 the License "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:  Logging
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef UILIBLOGGER_H
       
    21 #define UILIBLOGGER_H
       
    22 
       
    23 // INCLUDES
       
    24 
       
    25 #include <e32std.h>
       
    26 #include <e32def.h>
       
    27 
       
    28 #ifdef _DEBUG
       
    29 
       
    30 #include <flogger.h>
       
    31 #include <eikenv.h>
       
    32 
       
    33 /// DownloadMgrUiLib logging directory.
       
    34 _LIT( KDownloadMgrUiLibLogDir,                   "UiLib" );
       
    35 /// DownloadMgrUiLib log file name.
       
    36 _LIT( KDownloadMgrUiLibLogFile,                  "UiLibLog.txt" );
       
    37 /// Format string: enter function.
       
    38 _LIT( KDownloadMgrUiLibLogEnterFn,               "-> %S" );
       
    39 /// Format string: leave function.
       
    40 _LIT( KDownloadMgrUiLibLogLeaveFn,               "<- %S" );
       
    41 /// Format string: time.
       
    42 _LIT( KDownloadMgrUiLibLogTimeFormatString,      "%H:%T:%S:%*C2" );
       
    43 /// Format string: timestamp.
       
    44 _LIT( KDownloadMgrUiLibLogTimeStampFormatString, "%S %S" );
       
    45 _LIT( KDownloadMgrUiLibLogBanner,                "Download Manager UI Lib started" );
       
    46 _LIT( KDownloadMgrUiLibLogDependency,            "C:\\Logs\\" );
       
    47 _LIT( KDownloadMgrUiLibLogDoubleBackSlash,       "\\" );
       
    48 
       
    49 /// Create the log directory.
       
    50 #define LOG_CREATE 								             \
       
    51 	{                                                        \
       
    52 	TFileName path( KDownloadMgrUiLibLogDependency );        \
       
    53 	path.Append( KDownloadMgrUiLibLogDir );                  \
       
    54 	path.Append( KDownloadMgrUiLibLogDoubleBackSlash );      \
       
    55 	RFs& fs = CEikonEnv::Static()->FsSession();              \
       
    56 	fs.MkDirAll( path );                                     \
       
    57 	RFileLogger::WriteFormat( KDownloadMgrUiLibLogDir,       \
       
    58 	                          KDownloadMgrUiLibLogFile,      \
       
    59 	                          EFileLoggingModeAppend,        \
       
    60 	                          KDownloadMgrUiLibLogBanner );  \
       
    61 	}
       
    62 
       
    63 /// Write log: enter function.
       
    64 #define CLOG_ENTERFN( a )                         \
       
    65     {                                             \
       
    66     _LIT( temp, a );                              \
       
    67     RFileLogger::WriteFormat                      \
       
    68         (                                         \
       
    69         KDownloadMgrUiLibLogDir,                       \
       
    70         KDownloadMgrUiLibLogFile,                      \
       
    71         EFileLoggingModeAppend,                   \
       
    72         KDownloadMgrUiLibLogEnterFn,                   \
       
    73         &temp                                     \
       
    74         );                                        \
       
    75     }
       
    76 
       
    77 /// Write log: leave function.
       
    78 #define CLOG_LEAVEFN( a )                         \
       
    79     {                                             \
       
    80     _LIT( temp, a );                              \
       
    81     RFileLogger::WriteFormat                      \
       
    82         (                                         \
       
    83         KDownloadMgrUiLibLogDir,                       \
       
    84         KDownloadMgrUiLibLogFile,                      \
       
    85         EFileLoggingModeAppend,                   \
       
    86         KDownloadMgrUiLibLogLeaveFn,                   \
       
    87         &temp                                     \
       
    88         );                                        \
       
    89     }
       
    90 
       
    91 /// Write log: string 'a'.
       
    92 #define CLOG_WRITE( a )                           \
       
    93     {                                             \
       
    94     _LIT( temp, a );                              \
       
    95     RFileLogger::Write                            \
       
    96         (                                         \
       
    97         KDownloadMgrUiLibLogDir,                       \
       
    98         KDownloadMgrUiLibLogFile,                      \
       
    99         EFileLoggingModeAppend,                   \
       
   100         temp                                      \
       
   101         );                                        \
       
   102     }
       
   103 
       
   104 /// Write log: formatted.
       
   105 #define CLOG_WRITE_FORMAT( a, b )                 \
       
   106     {                                             \
       
   107     _LIT( temp, a );                              \
       
   108     RFileLogger::WriteFormat                      \
       
   109         (                                         \
       
   110         KDownloadMgrUiLibLogDir,                       \
       
   111         KDownloadMgrUiLibLogFile,                      \
       
   112         EFileLoggingModeAppend,                   \
       
   113         temp,                                     \
       
   114         b                                         \
       
   115         );                                        \
       
   116     }
       
   117 
       
   118 /// Write log: timestamp.
       
   119 #define CLOG_WRITE_TIMESTAMP( a )                 \
       
   120     {                                             \
       
   121     _LIT( temp, a );                              \
       
   122     TTime time;                                   \
       
   123     time.HomeTime();                              \
       
   124     TBuf<32> timeBuf;                             \
       
   125     TRAPD( err, time.FormatL( timeBuf, KDownloadMgrUiLibLogTimeFormatString ) );      \
       
   126     if ( !err )                                   \
       
   127         {                                         \
       
   128         RFileLogger::WriteFormat                  \
       
   129             (                                     \
       
   130             KDownloadMgrUiLibLogDir,                   \
       
   131             KDownloadMgrUiLibLogFile,                  \
       
   132             EFileLoggingModeAppend,               \
       
   133             KDownloadMgrUiLibLogTimeStampFormatString, \
       
   134             &temp,                                \
       
   135             &timeBuf                              \
       
   136             );                                    \
       
   137         }                                         \
       
   138     }
       
   139 
       
   140 /// Write log: download event.
       
   141 #define CLOG_WRITE_EVENT( text, downloadPtr, event ) \
       
   142     {                                             \
       
   143     _LIT( temp, text );                           \
       
   144     TBuf<64> formatstr;                           \
       
   145     formatstr.Copy( temp().Left(10) );              \
       
   146     formatstr.Append( _L(" 0x%x") );              \
       
   147     formatstr.Append( _L(" %d %d") );             \
       
   148     RFileLogger::WriteFormat                      \
       
   149         (                                         \
       
   150         KDownloadMgrUiLibLogDir,                  \
       
   151         KDownloadMgrUiLibLogFile,                 \
       
   152         EFileLoggingModeAppend,                   \
       
   153         formatstr,                                \
       
   154         downloadPtr,                              \
       
   155         event.iDownloadState,                     \
       
   156         event.iProgressState                      \
       
   157         );                                        \
       
   158     }
       
   159 
       
   160 /// Guard "log-only" argument name with this (expands to argument).
       
   161 #define CLOG_ONLY( argName ) argName
       
   162 
       
   163 #else /* not defined _DEBUG */
       
   164 
       
   165 /// Empty definition (disable log).
       
   166 #define LOG_CREATE
       
   167 /// Empty definition (disable log).
       
   168 #define CLOG_ENTERFN( a )
       
   169 /// Empty definition (disable log).
       
   170 #define CLOG_LEAVEFN( a )
       
   171 /// Empty definition (disable log).
       
   172 #define CLOG_WRITE( a )
       
   173 /// Empty definition (disable log).
       
   174 #define CLOG_WRITE_FORMAT( a, b )
       
   175 /// Empty definition (disable log).
       
   176 #define CLOG_WRITE_TIMESTAMP( a )
       
   177 /// Empty definition (disable log).
       
   178 #define CLOG_WRITE_EVENT( text, downloadPtr, event )
       
   179 /// Guard "log-only" argument name with this (expands to nothing).
       
   180 #define CLOG_ONLY( argName )
       
   181 
       
   182 #endif /* def _DEBUG */
       
   183 
       
   184 
       
   185 #endif /* def UILIBLOGGER_H */