void TSessionLog::Add(TLogLineType Type, UnicodeString ALine) { DebugAssert(FConfiguration); if (GetLogging()) { try { if (FParent != nullptr) { DoAdd(Type, ALine, nb::bind(&TSessionLog::DoAddToParent, this)); } else { TGuard Guard(FCriticalSection); DoAdd(Type, ALine, nb::bind(&TSessionLog::DoAddToSelf, this)); } } catch (Exception &E) { // We failed logging, turn it off and notify user. FConfiguration->SetLogging(false); try { throw ExtException(&E, LoadStr(LOG_GEN_ERROR)); } catch (Exception &E2) { AddException(&E2); FUI->HandleExtendedException(&E2); } } } }
//--------------------------------------------------------------------- void TConfiguration::SetLogging(bool Value) { if (GetLogging() != Value) { FPermanentLogging = Value; FLogging = Value; UpdateActualLogProtocol(); Changed(); } }
//--------------------------------------------------------------------------- void TSessionLog::AddStartupInfo(bool System) { TSessionData * Data = (System ? nullptr : FSessionData); if (GetLogging()) { if (FParent != nullptr) { // do not add session info for secondary session // (this should better be handled in the TSecondaryTerminal) } else { DoAddStartupInfo(Data); } } }
//--------------------------------------------------------------------------- void TSessionLog::Add(TLogLineType Type, const UnicodeString & Line) { assert(FConfiguration); if (GetLogging()) { try { if (FParent != nullptr) { DoAdd(Type, Line, MAKE_CALLBACK(TSessionLog::DoAddToParent, this)); } else { TGuard Guard(FCriticalSection); BeginUpdate(); auto cleanup = finally([&]() { DeleteUnnecessary(); EndUpdate(); }); { DoAdd(Type, Line, MAKE_CALLBACK(TSessionLog::DoAddToSelf, this)); } } } catch (Exception &E) { // We failed logging, turn it off and notify user. FConfiguration->SetLogging(false); try { throw ExtException(&E, LoadStr(LOG_GEN_ERROR)); } catch (Exception &E) { AddException(&E); FUI->HandleExtendedException(&E); } } } }
//--------------------------------------------------------------------------- void TSessionLog::DeleteUnnecessary() { BeginUpdate(); auto cleanup = finally([&]() { EndUpdate(); }); { if (!GetLogging() || (FParent != nullptr)) { Clear(); } else { while (!FConfiguration->GetLogWindowComplete() && (GetCount() > FConfiguration->GetLogWindowLines())) { Delete(0); ++FTopIndex; } } } }
//--------------------------------------------------------------------------- bool TSessionLog::LogToFile() const { return GetLogging() && FConfiguration->GetLogToFile() && (FParent == nullptr); }