-
Notifications
You must be signed in to change notification settings - Fork 1
/
Log.cpp
93 lines (90 loc) · 2.15 KB
/
Log.cpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "stdafx.h"
#include "Log.h"
#include <time.h>
#pragma warning(disable:4996)
using namespace std;
namespace Log
{
LOG getlog(wchar_t logfile[])
{
LOG log;
log.stream = new ofstream;
log.stream->open(logfile);
if (log.stream->fail())
throw ERROR_THROW(112);
wcscpy_s(log.logfile, logfile);
return log;
}
void WriteLine(LOG log, const char* c, ...)
{
const char** ptr = &c;
int i = 0;
while (ptr[i] != "")
*log.stream << ptr[i++];
*log.stream << endl;
}
void WriteLine(LOG log, const wchar_t* c, ...)
{
const wchar_t** ptr = &c;
char temp[100];
int i = 0;
while (ptr[i] != L"")
{
wcstombs(temp, ptr[i++], sizeof(temp));
*log.stream << temp;
}
*log.stream << endl;
}
void WriteLog(LOG log)
{
tm* timeinf;
time_t timet;
time(&timet);
timeinf = localtime(&timet);
char temp[100];
strftime(temp, sizeof(temp), "\n------------ÏÐÎÒÎÊÎË------------\n ----%d.%m.%y %T----\n ", timeinf);
*log.stream << temp;
}
void WriteIn(LOG log, In::IN in)
{
*log.stream << "\n---- Èñõîäíûå äàííûå ----\n" << in.text
<< "\n\nÂñåãî ñèìâîëîâ: " << in.size
<< "\n\nÂñåãî ñòðîê: " << in.lines
<< "\n\nÏðîïóùåíî: " << in.ignor << endl;
}
void WriteParm(LOG log, Parm::PARM parm)
{
char in_text[PARM_MAX_SIZE];
char out_text[PARM_MAX_SIZE];
char log_text[PARM_MAX_SIZE];
wcstombs(in_text, parm.in, PARM_MAX_SIZE);
wcstombs(out_text, parm.out, PARM_MAX_SIZE);
wcstombs(log_text, parm.log, PARM_MAX_SIZE);
*log.stream << "\n ---- Ïàðàìåòðû ---- \n\n-in: " << in_text
<< "\n-out: " << out_text
<< "\n-log: " << log_text << endl;
}
void WriteError(LOG log, Error::ERROR error)
{
if (log.stream)
{
*log.stream << "\nÎøèáêà " << error.id
<< ": " << error.message
<< "\nÑòðîêà " << error.inext.line
<< " ïîçèöèÿ " << error.inext.col << endl;
Close(log);
}
else
{
cout << "\nÎøèáêà " << error.id
<< ": " << error.message
<< "\nÑòðîêà " << error.inext.line
<< " ïîçèöèÿ " << error.inext.col << endl;
}
}
void Close(LOG log)
{
log.stream->close();
delete log.stream;
}
}