secureswitools/swisistools/source/interpretsislib/logger.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-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 /**
       
    20  @file LOGGER.H
       
    21  @publishedPartner
       
    22  @released
       
    23 */
       
    24 #ifndef	LOGGER_H
       
    25 #define	LOGGER_H
       
    26 
       
    27 #include <iosfwd>
       
    28 
       
    29 enum WarnLevel
       
    30 	{
       
    31 	WARN_OFF,
       
    32 	WARN_ERROR,
       
    33 	WARN_WARN,
       
    34 	WARN_INFO
       
    35 	};
       
    36 
       
    37 
       
    38 struct LoggerImpl;
       
    39 
       
    40 /**
       
    41  * Logger class to log messages from the system.
       
    42  */
       
    43 class Logger
       
    44 {
       
    45 public:
       
    46 	/**
       
    47 	 * Function will set the minimum warning level.
       
    48 	 * Messages having warning level greated than this 
       
    49 	 * won't be printed. Check WarnLevel for details.
       
    50 	 */
       
    51 	static bool SetLevel(WarnLevel aLev);
       
    52 	/**
       
    53 	 * Set the stream to which the mssage should be written.
       
    54 	 */
       
    55 	static bool SetStream(std::wostream& aOs);
       
    56 	/**
       
    57 	 * Get a reference to the stream.
       
    58 	 */
       
    59 	static std::wostream& Stream(); 
       
    60 	/**
       
    61 	 * Checks whether a warning level is allowed to print or not.
       
    62 	 * @param aLev level at which the message should be printed.
       
    63 	 */
       
    64 	static bool ShouldPrint(WarnLevel aLev); 
       
    65 	
       
    66 private:
       
    67 	static LoggerImpl& Logger::Impl();
       
    68 
       
    69 	static LoggerImpl* iLogger;
       
    70 };
       
    71 
       
    72 /**
       
    73  * Helper macro to print infom messages
       
    74  */
       
    75 #define LINFO(x)  if (Logger::ShouldPrint(WARN_INFO)) { Logger::Stream() << L"INFO: " << x << std::endl; }
       
    76 /**
       
    77  * Helper macro to print warning messages
       
    78  */
       
    79 #define LWARN(x)  if (Logger::ShouldPrint(WARN_WARN)) { Logger::Stream() << L"WARN: " << x << std::endl; }
       
    80 /**
       
    81  * Helper macro to print error messages
       
    82  */
       
    83 #define LERROR(x) if (Logger::ShouldPrint(WARN_ERROR)){ Logger::Stream() << L"ERR : " << x << std::endl; }
       
    84 
       
    85 #endif	/* LOGGER_H */