1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/securityanddataprivacytools/securitytools/certapp/utils/logger.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,92 @@
1.4 +/*
1.5 +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "logger.h"
1.23 +
1.24 +
1.25 +Log dbg("*** ");
1.26 +Log prog;
1.27 +
1.28 +Log::Log(const char *aPrefix)
1.29 + : iStream(0), iIndent(0), iPrefix(aPrefix)
1.30 +{
1.31 +}
1.32 +
1.33 +
1.34 +void Log::SetStream(std::ostream *aStream)
1.35 +{
1.36 + iStream = aStream;
1.37 + *iStream << std::hex;
1.38 +}
1.39 +
1.40 +std::ostream &Log::Stream()
1.41 +{
1.42 +BULLSEYE_OFF
1.43 + if(!iStream) FatalError();
1.44 +BULLSEYE_RESTORE
1.45 + return *iStream;
1.46 +}
1.47 +
1.48 +// Write the current indent level to the progress stream
1.49 +void Log::WriteIndent()
1.50 +{
1.51 +BULLSEYE_OFF
1.52 + if(!iStream) FatalError();
1.53 +BULLSEYE_RESTORE
1.54 + if(iPrefix)
1.55 + {
1.56 + *iStream << iPrefix;
1.57 + }
1.58 +
1.59 + for(int i=0; i < iIndent; ++i)
1.60 + {
1.61 + *iStream << '\t';
1.62 + }
1.63 +
1.64 +}
1.65 +
1.66 +// Increase indent level
1.67 +void Log::IncIndent()
1.68 +{
1.69 + ++iIndent;
1.70 +}
1.71 +
1.72 +// Decrease indent level
1.73 +void Log::DecIndent()
1.74 +{
1.75 + --iIndent;
1.76 +BULLSEYE_OFF
1.77 + if(iIndent < 0) FatalError();
1.78 +BULLSEYE_RESTORE
1.79 +}
1.80 +
1.81 +
1.82 +int Log::IndentLevel()
1.83 +{
1.84 + return iIndent;
1.85 +}
1.86 +
1.87 +
1.88 +void FatalError()
1.89 +{
1.90 + dbg << Log::Indent() << "Fatal Error - processing aborted" << Log::Endl();
1.91 + exit(-1);
1.92 +}
1.93 +
1.94 +
1.95 +// End of file