securityanddataprivacytools/securitytools/certapp/utils/logger.h
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 #ifndef __LOGGER_H__
       
     2 #define __LOGGER_H__/*
       
     3 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of the License "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description: 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <iostream>
       
    21 
       
    22 /**
       
    23  * @file
       
    24  * @internalComponent
       
    25  */
       
    26 
       
    27 extern void FatalError();
       
    28 
       
    29 
       
    30 class Log
       
    31 	{
       
    32 public:
       
    33 	struct Indent {}; // log << Log::Endl() will do line end
       
    34 	struct Endl {}; // log << Log::Endl() will do line end
       
    35 
       
    36 	Log(const char *aPrefix = 0);
       
    37 
       
    38 	void SetStream(std::ostream *aStream);
       
    39 	std::ostream &Stream();
       
    40 
       
    41 	// Write the current indent level to the progress stream
       
    42 	void WriteIndent();
       
    43 	// Increase indent level
       
    44 	void IncIndent();
       
    45 	// Decrease indent level
       
    46 	void DecIndent();
       
    47 	// Return current indent level
       
    48 	int IndentLevel();
       
    49 
       
    50 	template <typename T>
       
    51 	inline Log &operator<<(const T &anObject)
       
    52 		{
       
    53 			*iStream << anObject;
       
    54 			return *this;
       
    55 		}
       
    56 
       
    57 	inline Log &operator<<(const Indent &)
       
    58 		{
       
    59 			WriteIndent();
       
    60 			return *this;
       
    61 		}
       
    62 
       
    63 	inline Log &operator<<(const Endl &)
       
    64 		{
       
    65 			*iStream << std::endl;
       
    66 			return *this;
       
    67 		}
       
    68 
       
    69 private:
       
    70 	std::ostream *iStream;
       
    71 	int iIndent;
       
    72 	const char *iPrefix;
       
    73 	};
       
    74 
       
    75 
       
    76 extern Log dbg;
       
    77 extern Log prog;
       
    78 
       
    79 class AutoIndent
       
    80 	{
       
    81 public:
       
    82 	AutoIndent(Log &aLog)
       
    83 		: iLog(aLog)
       
    84 		{
       
    85 			iLog.IncIndent();
       
    86 		}
       
    87 	~AutoIndent()
       
    88 		{
       
    89 			iLog.DecIndent();
       
    90 		}
       
    91 private:
       
    92 	Log &iLog;
       
    93 	};
       
    94 
       
    95 #ifndef BULLSEYE_OFF
       
    96 #ifdef _BullseyeCoverage
       
    97 #define BULLSEYE_OFF "BullseyeCoverage save off";
       
    98 #define BULLSEYE_RESTORE "BullseyeCoverage restore";
       
    99 #else
       
   100 #define BULLSEYE_OFF 
       
   101 #define BULLSEYE_RESTORE 
       
   102 #endif
       
   103 #endif
       
   104 
       
   105 #endif