secureswitools/swisistools/source/common/logs.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     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 * xmllogger.cpp
       
    16 * CLogger - Used to log details to the specified log files. 
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file 
       
    23  @released
       
    24  @internalTechnology
       
    25 */
       
    26 
       
    27 #include "logs.h"
       
    28 #include "exception.h"
       
    29 #include <fstream>
       
    30 #include <iostream>
       
    31 
       
    32 std::ostream* LogDetails::LogStream = NULL;
       
    33 int LogDetails::LogLevel = 0;
       
    34 
       
    35 DllExport CLogger::CLogger(std::string& aLogFileName, CLogger::TLogLevel aLogLevel)
       
    36 	{
       
    37 	if(LogDetails::LogStream)
       
    38 		{
       
    39 		throw CException("Log file already initialized");
       
    40 		}
       
    41 	
       
    42 	
       
    43 	LogDetails::LogStream = new std::ofstream(aLogFileName.c_str(), std::ios::out | std::ios::app);
       
    44 		
       
    45 	LogDetails::LogLevel = aLogLevel;
       
    46 	}
       
    47 
       
    48 DllExport CLogger::~CLogger()
       
    49 	{
       
    50 	delete LogDetails::LogStream;
       
    51 	}
       
    52 
       
    53 /**
       
    54 	Logs the details based on the logging parameters.
       
    55 
       
    56 	@param	aMessage: Message to be logged in.
       
    57 	@param	aXmlParams: Logging parameters based on which message is to be logged.
       
    58  */
       
    59 DllExport void CLogger::Log(const char* aMessage)
       
    60 	{
       
    61 	if(LogDetails::LogStream == NULL)
       
    62 		{
       
    63 		std::string streamUnintialized = "Stream has not been initialized";
       
    64 		throw CException(streamUnintialized, ExceptionCodes::EUnintializedCode);
       
    65 		}
       
    66 	
       
    67 	*LogDetails::LogStream << aMessage << std::endl;
       
    68 	}
       
    69 
       
    70 /**
       
    71 	Logs the details based on the logging parameters.
       
    72 
       
    73 	@param	aMessage: Message to be logged in.
       
    74 	@param	aXmlParams: Logging parameters based on which message is to be logged.
       
    75  */
       
    76 DllExport void CLogger::Log(std::string& aMessage)
       
    77 	{
       
    78 	Log(aMessage.c_str());
       
    79 	}
       
    80 
       
    81 
       
    82 DllExport std::ostream& CLogger::GetStream()
       
    83 	{
       
    84 	return *LogDetails::LogStream;
       
    85 	}