json Serializer::serializeLogMessage(const LogMessagePtr& aMessageData) noexcept { return{ { "id", aMessageData->getId() }, { "text", aMessageData->getText() }, { "time", aMessageData->getTime() }, { "severity", getSeverity(aMessageData->getSeverity()) }, { "is_read", aMessageData->getRead() } }; }
void SystemFrame::addLine(const LogMessagePtr& aMessageData) { ctrlPad.SetRedraw(FALSE); POINT pt = { 0 }; bool scroll = !lButtonDown && scrollIsAtEnd(); ctrlPad.GetScrollPos(&pt); int curPos = ctrlPad.CharFromPos(pt); //current scroll position by character pos LONG SavedBegin, SavedEnd; LONG Begin = 0; LONG End = 0; ctrlPad.GetSel(SavedBegin, SavedEnd); End = Begin = ctrlPad.GetTextLengthEx(GTL_NUMCHARS); tstring Text = Text::toT(aMessageData->getText()) + _T(" \r\n"); tstring time = Text::toT(" [" + Util::getTimeStamp(aMessageData->getTime()) + "] "); tstring line = time + Text; LONG limitText = ctrlPad.GetLimitText(); LONG TextLength = End + line.size(); if((TextLength +1) > limitText) { dcdebug("textlength %s \n", Util::toString(TextLength).c_str()); LONG RemoveEnd = 0; RemoveEnd = ctrlPad.LineIndex(ctrlPad.LineFromChar(2000)); End = Begin -=RemoveEnd; SavedBegin -= RemoveEnd; SavedEnd -= RemoveEnd; //fix the scroll position if text was removed from the start POINT p = { 0 }; curPos -= RemoveEnd; p = ctrlPad.PosFromChar(curPos); pt.y = p.y; ctrlPad.SetSel(0, RemoveEnd); ctrlPad.ReplaceSel(_T("")); } ctrlPad.AppendText(line.c_str()); End += time.size() -1; ctrlPad.SetSel(Begin, End); ctrlPad.SetSelectionCharFormat(WinUtil::m_TextStyleTimestamp); if (aMessageData->getSeverity() == LogMessage::SEV_ERROR) { ctrlPad.SetSel(End, End+Text.length()-1); CHARFORMAT2 ec = WinUtil::m_ChatTextGeneral; ec.crTextColor = SETTING(ERROR_COLOR); ctrlPad.SetSelectionCharFormat(ec); } Colorize(Text, End+1); //timestamps should always be timestamps right? ctrlPad.SetSel(Begin, Begin); switch(aMessageData->getSeverity()) { case LogMessage::SEV_INFO: CImageDataObject::InsertBitmap(ctrlPad.GetOleInterface(),hbInfo, false); break; case LogMessage::SEV_WARNING: CImageDataObject::InsertBitmap(ctrlPad.GetOleInterface(), hbWarning, false); break; case LogMessage::SEV_ERROR: CImageDataObject::InsertBitmap(ctrlPad.GetOleInterface(), hbError, false); if(!errorNotified && !getActive()) { setIcon(tabError); errorNotified = true; } break; default: break; } ctrlPad.SetSel(SavedBegin, SavedEnd); //restore the user selection if(scroll/* && (SavedBegin == SavedEnd)*/) { scrollToEnd(); } else { ctrlPad.SetScrollPos(&pt); } ctrlPad.SetRedraw(TRUE); ctrlPad.InvalidateRect(NULL); }