Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Logging Class( Using Singleton )

DZone's Guide to

Logging Class( Using Singleton )

Free Resource

Discover 50 of the latest mobile performance statistics with the Ultimate Guide to Digital Experience Monitoring, brought to you in partnership with Catchpoint.

// 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

Is your APM strategy broken? This ebook explores the latest in Gartner research to help you learn how to close the end-user experience gap in APM, brought to you in partnership with Catchpoint.

Topics:
logging

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}