一:
日志发送到远程syslog服务器:
var AWriter := TQLogSocketWriter.Create;
AWriter.ServerHost := 127.0.0.1;//远程服务器地址
AWriter.ServerPort := 514; //远程服务器端口
AWriter.UseTCP := False;
Logs.Castor.AddWriter(AWriter);
二:
日志记录到本地文件:
//LogPath为日志存放路径
var BWriter := TQLogFileWriter.Create(LogPath);
BWriter.MaxSize := LogSize * 1048576; //单日志文件大小 10M,日志文件大小到达10M即分卷压缩
BWriter.CreateMode := lcmRename;
BWriter.OneFilePerDay := True;
Logs.Castor.AddWriter(BWriter);
或者直接使用SetDefaultLogFile(LogPath + '\Log.TXT', LogSize * 1048576, True, True);
三:
日志输出到控件展示:
var MemoWriter := TQLogStringsWriter.Create;
MemoWriter.Items := Mmo1.Lines;//日志输出到memo控件中展示
MemoWriter.MaxItems := 20 ; //日志展示最大行数
Logs.Castor.AddWriter(MemoWriter);
四:
LogWriter对象有AcceptLevels属性,设置该属性,即当前日志记录对象只会记录对应属性标记的数据,即在Logs.Post时,参数1的日志等级
例如:Writer.AcceptLevels := [llMessage, llDebug]
此时只能记录 Logs.Post(llMessage,''),Logs.Post(llDebug,''),其余的Logs.Post(llError,'')等不会被记录
标签:AWriter,BWriter,Logs,记录,Post,QDAC,QLog,日志,MemoWriter From: https://www.cnblogs.com/Thenext/p/17832791.html