[go: up one dir, main page]

Menu

[96b3e1]: / log.cpp  Maximize  Restore  History

Download this file

42 lines (35 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/////////////////////////////////////////////////////////////////////////////////
// Author: Steven Lamerton
// Copyright: Copyright (C) 2009 - 2011 Steven Lamerton
// License: GNU GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
/////////////////////////////////////////////////////////////////////////////////
#include "log.h"
#include <wx/app.h>
#include <wx/msgdlg.h>
#include <wx/textfile.h>
#include <boost/interprocess/ipc/message_queue.hpp>
using namespace boost::interprocess;
void LogMessageQueue::DoLogRecord(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info){
//Discard verbose output, they should only be output to a file
if(level >= wxLOG_Info)
return;
std::string out = msg.ToStdString();
try{
message_queue eq(open_only, "error");
eq.send(out.data(), out.size(), 5);
}
catch(std::exception &ex){
wxLogError("%s", ex.what());
}
}
LogFile::LogFile(wxTextFile* file) : file(file)
{
count = 0;
}
void LogFile::DoLogRecord(wxLogLevel level, const wxString& msg, const wxLogRecordInfo& info){
file->AddLine(msg);
count++;
//Don't write output every line but do it fairly frequently
if(count % 10 == 0)
file->Write();
}