securityanddataprivacytools/securitytools/certapp/utils/logger.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "logger.h"
       
    20 
       
    21 
       
    22 Log dbg("*** ");
       
    23 Log prog;
       
    24 
       
    25 Log::Log(const char *aPrefix)
       
    26 	: iStream(0), iIndent(0), iPrefix(aPrefix)
       
    27 {
       
    28 }
       
    29 
       
    30 
       
    31 void Log::SetStream(std::ostream *aStream)
       
    32 {
       
    33 	iStream = aStream;
       
    34 	*iStream << std::hex;
       
    35 }
       
    36 
       
    37 std::ostream &Log::Stream()
       
    38 { 
       
    39 BULLSEYE_OFF
       
    40 	if(!iStream) FatalError();
       
    41 BULLSEYE_RESTORE
       
    42 	return *iStream; 
       
    43 }
       
    44 
       
    45 // Write the current indent level to the progress stream
       
    46 void Log::WriteIndent()
       
    47 {
       
    48 BULLSEYE_OFF
       
    49 	if(!iStream) FatalError();
       
    50 BULLSEYE_RESTORE
       
    51 	if(iPrefix)
       
    52 		{
       
    53 		*iStream << iPrefix;
       
    54 		}
       
    55 	
       
    56 	for(int i=0; i < iIndent; ++i)
       
    57 		{
       
    58 		*iStream << '\t';
       
    59 		}
       
    60 	
       
    61 }
       
    62 
       
    63 // Increase indent level
       
    64 void Log::IncIndent()
       
    65 {
       
    66 	++iIndent;
       
    67 }
       
    68 
       
    69 // Decrease indent level
       
    70 void Log::DecIndent()
       
    71 {
       
    72 	--iIndent;
       
    73 BULLSEYE_OFF
       
    74 	if(iIndent < 0) FatalError();
       
    75 BULLSEYE_RESTORE
       
    76 }
       
    77 
       
    78 
       
    79 int Log::IndentLevel()
       
    80 {
       
    81 	return iIndent;
       
    82 }
       
    83 
       
    84 
       
    85 void FatalError()
       
    86 {
       
    87 	dbg << Log::Indent() << "Fatal Error - processing aborted" << Log::Endl();
       
    88 	exit(-1);
       
    89 }
       
    90 
       
    91 
       
    92 // End of file