日誌記錄 01 記憶體流操作

2022-06-30 04:06:09 字數 1196 閱讀 2549

日誌記錄,我們一般通過本地文字檔案進行記錄,對於使用的檔案字尾名,一般為比較形象的 .log ,當然也可以是其它任何自定義的格式, 如: .abc,  .xyz

本次隨筆主要描述的是借用內在存流來處理日誌記錄 tmemorystream;

01. 日誌記錄,我們無建立乙個用於記錄的檔案. 使用函式 filecreate(檔案路徑), 可以是絕對路徑,也可以是相對路徑

♦ 注意一點:  filecreate 函式會覆蓋原有的內容; 而且還不會進行提示;

♦ 在實際使用過程中,最好通過 fileexists 判斷一次再進行 filecreate 動作; 否則原有的內容都將丟失 ;

02. 對於日誌內容的傳遞變數型別.

♦為解決中文雙位元組及delphi中對位元組長度計算有可能不一致的問題,我們使用 ansistring 來傳遞內容

03.為有效處理不同記錄內容的換行處理,我們需要在每次的日誌記錄內容新增上回車換行符 #13#10, 也可以直接使用 slinebreak;

04.注意 fileseek函式中三號引數的作用: 0:從檔案頭開始定位;1:從當前位置開始定位;2:從檔案尾定位

var    flogmsg:ansistring;    fms:tmemorystream;    flogfilename:string;    th:thandle; begin    //日誌檔案    flogfilename := 'logtest.txt';    if not fileexists(flogfilename) then       th := filecreate(flogfilename)    else       th := fileopen(flogfilename,fmopenwrite+fmsharedenywrite);    //檔案定位.注意3號引數: 本處是定位到檔案尾    fileseek(th,0,2);    //日誌內容    flogmsg := ansistring( formatdatetime('hh:mm:ss.zzz',now)+'  '+' 這是乙個測試日誌內容.' );    //記憶體流    fms := tmemorystream.create;    fms.write(flogmsg[1],length(flogmsg));    //寫日誌    fms.position := 0; //保證從記憶體流最開始記錄    filewrite(th,fms.memory^,fms.size);    //操作完畢    fileclose(th); end;

資料操作流 記憶體操作流 列印流

資料操作流 目前基本沒用 datasource.自己查詢把 記憶體操作流 用來處理臨時儲存資訊的,程式結束時,資料就從記憶體中消失 操作位元組 bytearrayoutputstream 輸出流 寫入操作 bytearrayinputstream 輸入流 讀取資料 字元陣列 chararrayrea...

記錄mysql操作日誌

現在想比對php網頁執行前後的差異,但是一直找不到比較好的軟體 增刪查改都記錄的那種。然後通過瀏覽官方文件發現mysql 5。1有乙個通用查詢日誌。於是嘗試 mysql.server start log file name.log starting mysql 2017 12 16 14 51 44...

Linux記錄操作日誌

history命令可以檢視最近1000條命令。調整history命令的大小 vi etc profile histsize 1000 改為 history日誌檔案預設是儲存在.bash history檔案下。history命令預設是沒有時間的,可以在 etc bashrc檔案下追加以下 histfi...