//---------------------------------------------------------------------------------
// <copyright file="LqrSMACFileSetLogger.h" company="LiquidRobotics">
//
// Copyright (c) 2014 Liquid Robotics, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// This software is associated with a release.  Liquid Robotics makes no
// representation that the design, interfaces or component distribution will
// remain unchanged in future releases.
//
// </copyright>
//
// <summary>
//   Declarations for FileSetLogger, a Logger-derived class that implements logging
//   to a file set.
// </summary>
//
// <owner>Mike Cookson</owner>
//---------------------------------------------------------------------------------

#ifndef __LqrSMACFileSetLogger_h__
#define __LqrSMACFileSetLogger_h__

#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/shared_ptr.hpp>
#include "LqrSMACLogger.h"

namespace LiquidRobotics {
namespace SMACFramework {

class FileSet;
class FileSetSettings;
class FileSetLoggerSettings;

class SHARED_LIB_PUBLIC FileSetLogger
: public Logger
{
public:

	typedef boost::shared_ptr<FileSetLogger> Ptr;
	typedef std::string string;

	FileSetLogger(FileSet& _fileSet, const char* _processName, LogType level = LT_WARNING);
	FileSetLogger(FileSet& _fileSet, const FileSetLoggerSettings& _settings);

	static Ptr Create(const FileSetSettings& fsSettings, const FileSetLoggerSettings& fslSettings);
	static Logger* CreateLogger(const FileSetSettings& fsSettings, const FileSetLoggerSettings& fslSettings);

	virtual ~FileSetLogger();

	void Write(const LogType logType, const char* data);
	void Format(const LogType logType, const char* format, ...);
	void FormatV(const LogType logType, const char* format, va_list argptr);
	bool LogEnabled(const LogType logType) const;
	void SetLevel(LogType newLevel);

protected:

	virtual bool IsOpen(const LogType logType) const;
	virtual bool IsConfigured() const;
	virtual void Write(const char* data);

	string GetTimestamp() const;
	string GetHostName() const;
	string GetProcessName() const;
	virtual string GetLineHeader() const;

	typedef boost::shared_ptr<FileSet> FSPtr;

	FSPtr fsPtr;
	FileSet& fileSet;
	LogType level;
	string processName;
	string hostName;
};

}
}


#endif
