summaryrefslogtreecommitdiff
path: root/cpp/demo/Ice/MFC/server/LogI.cpp
blob: 58b6f3b726588326bed15dd6555c0923fdaea255 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// **********************************************************************
//
// Copyright (c) 2003
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************

#include "stdafx.h"
#include "LogI.h"

using namespace std;

LogI::LogI() :
    _log(0)
{
}

void
LogI::trace(const string& category, const string& msg)
{
    string s = "[ " + category + ": " + msg + " ]";

    string::size_type idx = 0;
    while((idx = s.find("\n", idx)) != string::npos)
    {
        s.replace(idx, 1, "\r\n  ");
        idx += 3;
    }

    message(s);
}

void
LogI::warning(const string& msg)
{
    message("warning: " + msg);
}

void
LogI::error(const string& msg)
{
    message("error: " + msg);
}

void
LogI::message(const string& msg)
{
    string line = msg + "\r\n";
    if(_log)
    {
        _log->SetSel(-1, -1);
        _log->ReplaceSel(CString(line.c_str()));
    }
    else
    {
        _buffer.append(line);
    }
}

void
LogI::setControl(CEdit* log)
{
    _log = log;
    if(!_buffer.empty())
    {
        _log->ReplaceSel(CString(_buffer.c_str()));
        _buffer.clear();
    }
}