Skip to content

Commit

Permalink
Add option to stream logs to file
Browse files Browse the repository at this point in the history
  • Loading branch information
dfranx committed Sep 14, 2019
1 parent 18e4044 commit 7f35e06
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
+ add "Show whitespace" option
+ add ScreenQuadNDC
+ add the ability to set CodeUI.Save and Project.Save to same shortcut
+ add option to stream logs
+ fix some TextEditor bugs

[v1.1.4]
Expand Down
10 changes: 8 additions & 2 deletions Objects/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ namespace ed
if (Settings::Instance().General.PipeLogsToTerminal)
std::cout << data.str() << std::endl;

m_msgs.push_back(data.str());
if (Settings::Instance().General.StreamLogs) {
std::ofstream log("log.txt", std::ios_base::app | std::ios_base::out);
log << data.str() << std::endl;
log.close();
}
else
m_msgs.push_back(data.str());
}
void Logger::Save()
{
if (!Settings::Instance().General.Log)
if (!Settings::Instance().General.Log || Settings::Instance().General.StreamLogs)
return;

time_t now = time(0);
Expand Down
2 changes: 2 additions & 0 deletions Objects/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace ed
General.Recovery = ini.GetBoolean("general", "recovery", false);
General.CheckUpdates = ini.GetBoolean("general", "checkupdates", true);
General.Log = ini.GetBoolean("general", "log", true);
General.StreamLogs = ini.GetBoolean("general", "streamlogs", false);
General.PipeLogsToTerminal = ini.GetBoolean("general", "pipelogsterminal", false);
General.ReopenShaders = ini.GetBoolean("general", "reopenshaders", true);
General.UseExternalEditor = ini.GetBoolean("general", "useexternaleditor", true);
Expand Down Expand Up @@ -142,6 +143,7 @@ namespace ed
ini << "recovery=" << General.Recovery << std::endl;
ini << "checkupdates=" << General.CheckUpdates << std::endl;
ini << "log=" << General.Log << std::endl;
ini << "streamlogs=" << General.StreamLogs << std::endl;
ini << "pipelogsterminal=" << General.PipeLogsToTerminal << std::endl;
ini << "reopenshaders=" << General.ReopenShaders << std::endl;
ini << "useexternaleditor=" << General.UseExternalEditor << std::endl;
Expand Down
1 change: 1 addition & 0 deletions Objects/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace ed
bool ItemPropsOnDblCLk;
bool SelectItemOnDblClk;
bool Log;
bool StreamLogs;
bool PipeLogsToTerminal;
std::string StartUpTemplate;
char Font[MAX_PATH];
Expand Down
7 changes: 6 additions & 1 deletion UI/OptionsUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ namespace ed
ImGui::TextDisabled(" (scale=%.4f)", settings->TempScale);
}

/* LOGGER STUFF */
/* LOG STUFF */
ImGui::NewLine();
ImGui::Separator();
ImGui::NewLine();
Expand All @@ -353,6 +353,11 @@ namespace ed
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f);
}

/* STREAM LOGS: */
ImGui::Text("Streams logs to log.txt: ");
ImGui::SameLine();
ImGui::Checkbox("##optg_streamlogs", &settings->General.StreamLogs);

/* PIPE LOGS: */
ImGui::Text("Write log messages to console window: ");
ImGui::SameLine();
Expand Down
1 change: 1 addition & 0 deletions bin/data/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolbar=0
recovery=0
checkupdates=1
log=1
streamlogs=0
pipelogsterminal=0
reopenshaders=0
useexternaleditor=0
Expand Down
12 changes: 12 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,20 @@ int main(int argc, char* argv[])
{
if (argc > 0) {
ghc::filesystem::current_path(ghc::filesystem::path(argv[0]).parent_path());

// delete log.txt on startup
if (ghc::filesystem::exists("./log.txt")) {
std::error_code errCode;
ghc::filesystem::remove("./log.txt", errCode);
}

ed::Logger::Get().Log("Setting current_path to " + ghc::filesystem::current_path().generic_string());
}
else if (ghc::filesystem::exists("./log.txt")) {
std::error_code errCode;
ghc::filesystem::remove("./log.txt", errCode);
}


// set stb_image flags
stbi_flip_vertically_on_write(1);
Expand Down

0 comments on commit 7f35e06

Please sign in to comment.