-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
74 lines (68 loc) · 2.24 KB
/
Copy pathutils.cpp
File metadata and controls
74 lines (68 loc) · 2.24 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
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
//
// Created by IIAP-IPC on 03/02/2021.
//
#include "utilheaders.h"
int loggingMode;
std::string loggingFilename;
std::ofstream outfile;
char logString[100000];
int getModeAndDeviceName(std::string deviceOptions[], std::string *deviceName, int *mode) {
std::string modeString;
while (1) {
std::sprintf(logString, "Enter 0 for Individual Mode, 1 for coupled mode");
log(logString, INFO);
getline(std::cin, modeString);
*mode = atoi(modeString.c_str());
if (*mode == INDIVIDUAL || *mode == COUPLED) {
switch (*mode) {
case INDIVIDUAL:
*deviceName = deviceOptions[0];
break;
case COUPLED:
*deviceName = deviceOptions[1];
break;
}
break;
}
}
return 0;
}
int log(std::string logString, int severity) {
time_t curr_time;
tm * curr_tm;
time(&curr_time);
curr_tm = localtime(&curr_time);
char timeString[100];
std::strftime(timeString, 100, "%Y_%m_%dT%H_%M_%S:: ", curr_tm);
if (severity == PROMPT) {
std::cout << logString << std::endl;
}
else if (severity == ERROR || loggingMode >= severity) {
std::cout << logString << std::endl;
outfile << timeString << logString << std::endl;
}
return 0;
}
int setupLogging(){
time_t curr_time;
tm * curr_tm;
time(&curr_time);
curr_tm = localtime(&curr_time);
char filename[100];
std::strftime(filename, 100, "output_%Y_%m_%dT%H_%M_%S.txt", curr_tm);
loggingFilename = std::string(filename);
outfile.open(loggingFilename.c_str());
std::string loggingInputString;
while (1) {
std::cout<<"Enter the logging mode (0: info, 1: debug, 2: error)"<<std::endl;
getline(std::cin, loggingInputString);
loggingMode = atoi(loggingInputString.c_str());
if (loggingMode == ERROR || loggingMode == DEBUG || loggingMode == INFO) {
std::string logMode = loggingMode == ERROR?std::string("ERROR"):loggingMode == DEBUG?std::string("DEBUG"):std::string("INFO");
sprintf(logString, "loggingMode: %s", logMode.c_str());
log(logString, ERROR);
break;
}
}
return 0;
}