Platinum Partner
logging

Logging Class( Using Singleton )

// A logging class, using a singleton.
// Will create a backup file
// Coded in C++
// Doesn't use a pointer for the singleton
// Coded by Ian T. Jacobsen 2011

// Header

#ifndef LOGGING_H
#define LOGGING_H

#include 
#include 

#define LOG CLogging::Inst("log.log").Log

class CLogging
{
public:
    static CLogging& Inst(char* filename);
    void Log(std::string message);
    ~CLogging();
protected:
    CLogging(char* filename);
private:
    char* m_filename;
    std::fstream m_fOut;
};

#endif // LOGGING_H


// Source file

#include "include/logging.h"
#include 

        CLogging& CLogging::Inst(char* filename)
        {
            static CLogging m_pInstance(filename);
            return m_pInstance;
        }

        CLogging::CLogging(char* filename)
            : m_filename(filename)
        {
            std::fstream temp(filename, std::ios_base::in);

            std::fstream backup(std::string(std::string(m_filename).append(".backup")).c_str(), std::ios_base::out | std::ios_base::trunc);

            temp.seekg(0,std::ios::end);
            int length = temp.tellg();
            temp.seekg(0,std::ios::beg);

            char* buffer = new char[length];

            temp.read(buffer,length);

            backup.write(buffer, length-4);

            delete[] buffer;
            temp.close();
            backup.close();

            m_fOut.open(filename, std::ios_base::out | std::ios_base::trunc);

            char date[9];
            _strdate(date);

            m_fOut
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}