Skip to content

Commit db439f4

Browse files
Samat Gaynutdinovantipeon
authored andcommitted
remove color symbols from common logs
1 parent 2e10579 commit db439f4

File tree

8 files changed

+37
-10
lines changed

8 files changed

+37
-10
lines changed

docker/release_distribution_scripts/utbot_run_system.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,18 @@ then
119119

120120
#Server-specific parameters
121121
UTBOT_EXECUTABLE_PATH=$UTBOT_BINARIES_FOLDER/$UTBOT_PROCESS_PATTERN
122-
UTBOT_STDOUT_LOG_FILE=$UTBOT_LOGS_FOLDER/logs/$UTBOT_PROCESS_PATTERN-$(now).log
123122
UTBOT_SERVER_OPTIONS="$UTBOT_MODE --port $UTBOT_PORT --log=$UTBOT_LOGS_FOLDER --tmp=$UTBOT_ALL"
123+
UTBOT_STDOUT_LOG_FILE=$UTBOT_LOGS_FOLDER/logs/"latest.log"
124124

125125
log "Starting a new server process; logs are written into [$UTBOT_LOGS_FOLDER] folder"
126-
start_process $UTBOT_PROCESS_PATTERN $UTBOT_EXECUTABLE_PATH "$UTBOT_SERVER_OPTIONS" $UTBOT_STDOUT_LOG_FILE $UTBOT_PID_FILE
126+
start_process "$UTBOT_PROCESS_PATTERN" "$UTBOT_EXECUTABLE_PATH" "$UTBOT_SERVER_OPTIONS" "$UTBOT_STDOUT_LOG_FILE" "$UTBOT_PID_FILE"
127127
repeats=0
128-
while [ $repeats -le 20 ] && [ $(wc -l < $UTBOT_STDOUT_LOG_FILE) -lt 5 ]
128+
while [ $repeats -le 20 ] && [ $(wc -l < $UTBOT_STDOUT_LOG_FILE) -lt 6 ]
129129
do
130130
sleep 0.1
131131
repeats=$(( repeats + 1 ))
132132
done
133-
head $UTBOT_STDOUT_LOG_FILE -n 5
133+
head $UTBOT_STDOUT_LOG_FILE -n 6
134134
fi
135135

136136
if [ "$1" = "cli" ]

docker/release_distribution_scripts/utbot_scripts/common_functions.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ log(){
2727
# - $5 - PID file to be created
2828
start_process(){
2929
log "INFO Starting new [$1] process right now"
30-
nohup $2 $3 >> $4 2>&1 &
30+
nohup $2 $3 > /dev/null 2>&1 &
3131
local PROCESS_PID=$!
3232
echo $PROCESS_PID > $5
33-
log "INFO New [$1] instance with pid [$PROCESS_PID] has been started, process options are [$3], pid file created: [$5]; STDOUT and STDERR redirected to [$4]"
33+
log "INFO New [$1] instance with pid [$PROCESS_PID] has been started, process options are [$3], pid file created: [$5]; logs write to [$4]"
3434
}
3535

3636
# Function arguments:

server/src/Paths.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "ProjectContext.h"
88
#include "utils/StringUtils.h"
9+
#include "utils/CLIUtils.h"
910

1011
#include "loguru.h"
1112

server/src/Paths.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ namespace Paths {
130130
return logPath / "logs";
131131
}
132132

133+
static inline fs::path getUtbotLogAllFilePath() {
134+
const static std::string filename = "utbot-" + TimeUtils::getCurrentTimeStr() + ".log";
135+
return logPath / Paths::getBaseLogDir() / filename;
136+
}
137+
133138
static inline fs::path getClientLogDir(const string &client) {
134139
return getBaseLogDir() / client;
135140
}
@@ -152,6 +157,10 @@ namespace Paths {
152157
return execLogPath;
153158
}
154159

160+
static inline fs::path getSymLinkPathToLogLatest() {
161+
return Paths::getBaseLogDir() / "latest.log";
162+
}
163+
155164
//endregion
156165

157166
static inline fs::path getTmpDir(const string &projectName) {

server/src/Server.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ const string Server::gtestLogPrefix = "gtestLogTo";
4545

4646
void Server::run(uint16_t customPort) {
4747
LOG_S(INFO) << "UnitTestBot Server, build " << UTBOT_BUILD_NUMBER;
48-
LOG_S(INFO) << "Log path: " << Paths::logPath;
48+
LOG_S(INFO) << "Logs directory: " << Paths::logPath;
49+
LOG_S(INFO) << "Latest log path: " << Paths::getUtbotLogAllFilePath();
4950
LOG_S(INFO) << "Tmp directory path: " << Paths::tmpPath;
5051
LOG_S(INFO) << "Executable path: " << fs::current_path();
5152

server/src/utils/CLIUtils.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ void CLIUtils::setupLogger(const std::string &logPath,
3636
if (!threadView) {
3737
loguru::g_preamble_thread = false;
3838
}
39-
setOptPath(logPath, Paths::logPath);
39+
40+
CLIUtils::setOptPath(logPath, Paths::logPath);
41+
const fs::path symLink = Paths::getSymLinkPathToLogLatest();
42+
const std::string logfile_path_string = std::string(Paths::getUtbotLogAllFilePath());
43+
loguru::add_file(logfile_path_string.data(), loguru::Append, loguru::Verbosity_MAX);
44+
std::filesystem::remove(symLink.string());
45+
std::filesystem::create_symlink(logfile_path_string, symLink.string());
46+
4047
setStderrVerbosity(verbosity);
4148
}
4249

@@ -241,7 +248,6 @@ void CLIUtils::parse(int argc, char **argv, CLI::App &app) {
241248
} else {
242249
CLIUtils::setupLogger(serverCommandOptions.getLogPath(),
243250
serverCommandOptions.getVerbosity());
244-
CLIUtils::setOptPath(serverCommandOptions.getLogPath(), Paths::logPath);
245251
CLIUtils::setOptPath(serverCommandOptions.getTmpPath(), Paths::tmpPath);
246252
Server server;
247253
if (serverCommandOptions.getPort() != 0) {

server/src/utils/TimeUtils.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ namespace TimeUtils {
3636
systemClockTimePoint convertFileToSystemClock(const fs::file_time_type &fTime) {
3737
return std::chrono::system_clock::from_time_t(to_time_t(fTime));
3838
}
39-
}
39+
40+
std::string getCurrentTimeStr() {
41+
time_t t = std::time(nullptr);
42+
tm tm = *std::localtime(&t);
43+
std::ostringstream oss;
44+
oss << std::put_time(&tm, "%Y%m%d%H%M%S");
45+
return oss.str();
46+
}
47+
}

server/src/utils/TimeUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace TimeUtils {
3737
systemClockTimePoint convertFileToSystemClock(const fs::file_time_type& fTime);
3838

3939
string getDate();
40+
41+
std::string getCurrentTimeStr();
4042
}
4143

4244
#endif //UNITTESTBOT_TIMEUTIL_H

0 commit comments

Comments
 (0)