
#include <iostream>

#include "threads.h"
#include "log.h"

#ifdef _DEBUG
#ifndef DEBUG_NEW
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
#endif

threads :: mutex logmutex;

// --------------------------------

std :: string onlyFile(const std :: string& file)
{
    return file.substr(file.find_last_of("\\")+1);
}

// --------------------------------

void rlog(const std :: string& file, const std :: string& function, int line, const std :: string& str)
{
    logmutex.lock();
    std :: cerr << onlyFile(file) << ", " << line << ": " << str << std :: endl;
    logmutex.unlock();
}

// --------------------------------

void log(const std :: string& str)
{
    logmutex.lock();
    std :: cerr << str << std :: endl;
    logmutex.unlock();
}

// --------------------------------

void lnextline()
{
    logmutex.lock();
    std :: cerr << std :: endl;
    logmutex.unlock();
}

// --------------------------------

void lockConsoleForWrite()
{
    logmutex.lock();
}

// --------------------------------

void unlockConsoleForWrite()
{
    logmutex.unlock();
}

// --------------------------------
