delphi日志模块代码

2024-09-06 14:38
文章标签 代码 模块 日志 delphi

本文主要是介绍delphi日志模块代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

unit LOG_logging;


interface
uses
  System.Win.ScktComp,  System.SysUtils, Winsock, Windows, System.Classes,
  UGlobalvariable_type;


type


  TLOG_logging = class
    txt: TextFile;  {文件}
    txtfile: AnsiString; {文件名}
    procedure ONLOG(VVGFlogtype: integer; VVGFlogstr: AnsiString);


  strict private
    VGFlogstr: AnsiString;
    VGFlogtype: integer;


    procedure Setlogstr(const Value: AnsiString);
    procedure Setlogtype(const Value: integer);
    procedure log_save;   {日志函数}
  published


  public
    constructor  Create;
    destructor destroy; override;
    procedure Execute;


    property logtype:integer read VGFlogtype write Setlogtype;
    property logstr:AnsiString read VGFlogstr write Setlogstr;
  end;


implementation


constructor TLOG_logging.Create;
begin
  inherited Create;
  if not DirectoryExists(ExtractFilePath(ParamStr(0))+'log\') then
    ForceDirectories(ExtractFilePath(ParamStr(0))+'log\');
  txtfile := ExtractFilePath(ParamStr(0))+'log\'+ FormatDateTime('YYYYMMDD',Now ) +'.log' ;
  AssignFile( txt,txtfile);
  //Resume ; //唤醒线程,开始执行Execute里的内容
end;


destructor TLOG_logging.destroy;
begin
  inherited;
end;


procedure TLOG_logging.Execute;    {建立TCP服务线程}
begin
  TRY
    txtfile := ExtractFilePath(ParamStr(0))+'log\'+ FormatDateTime('YYYYMMDD',Now ) +'.log' ;
    if fileexists(txtfile) then
    begin


    end
    else
    begin
      AssignFile( txt,txtfile);
      Rewrite(txt);    //日志文件新建或者重写原有的文件
      CloseFile(txt);
    end;


    if VGFlogtype > 0 then
    begin
      log_save;  {日志函数}
      VGFlogtype := 0;
    end;


  FINALLY
  END;


end;


procedure TLOG_logging.log_save;  {日志函数}
begin
  try
    try
      Append(txt);  //写打开文件,指针到尾
    except
      Exit;
    end;


    case VGFlogtype of
      1://异常记录
      begin
        Writeln(txt,'systemerr:'+FormatDateTime('yy-mm-dd hh:nn:ss',now) +'|'+string(VGFlogstr) );  //写入记录文件
        Writeln(txt,'' );


      end;
      2://TCP记录
      begin


        Writeln(txt,'TCP_LOG:'+FormatDateTime('yy-mm-dd hh:nn:ss',now) +'|'+string(VGFlogstr));  //写入记录文件
        Writeln(txt,'' );


      end;
      3://记录日志
      begin


        Writeln(txt,'LOG:'+FormatDateTime('yy-mm-dd hh:nn:ss',now) +'|'+string(VGFlogstr) );  //写入记录文件
        Writeln(txt,'' );


      end;
    end;


  finally
    CloseFile(txt);
  end;


end;


procedure TLOG_logging.Setlogstr(const Value: AnsiString);
begin
  VGFlogstr := Value;
end;


procedure TLOG_logging.Setlogtype(const Value: integer);
begin
  VGFlogtype := Value;
end;


procedure TLOG_logging.ONLOG(VVGFlogtype: integer; VVGFlogstr: AnsiString);
begin


  VGFlogstr := VVGFlogstr;
  VGFlogtype := VVGFlogtype;
  Execute;


end;




end.

这篇关于delphi日志模块代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1142288

相关文章

Java进行日期解析与格式化的实现代码

《Java进行日期解析与格式化的实现代码》使用Java搭配ApacheCommonsLang3和Natty库,可以实现灵活高效的日期解析与格式化,本文将通过相关示例为大家讲讲具体的实践操作,需要的可以... 目录一、背景二、依赖介绍1. Apache Commons Lang32. Natty三、核心实现代

使用Python自动化生成PPT并结合LLM生成内容的代码解析

《使用Python自动化生成PPT并结合LLM生成内容的代码解析》PowerPoint是常用的文档工具,但手动设计和排版耗时耗力,本文将展示如何通过Python自动化提取PPT样式并生成新PPT,同时... 目录核心代码解析1. 提取 PPT 样式到 jsON关键步骤:代码片段:2. 应用 JSON 样式到

MySQL精准控制Binlog日志数量的三种方案

《MySQL精准控制Binlog日志数量的三种方案》作为数据库管理员,你是否经常为服务器磁盘爆满而抓狂?Binlog就像数据库的“黑匣子”,默默记录着每一次数据变动,但若放任不管,几天内这些日志文件就... 目录 一招修改配置文件:永久生效的控制术1.定位my.cnf文件2.添加核心参数不重启热更新:高手应

SpringBoot实现二维码生成的详细步骤与完整代码

《SpringBoot实现二维码生成的详细步骤与完整代码》如今,二维码的应用场景非常广泛,从支付到信息分享,二维码都扮演着重要角色,SpringBoot是一个非常流行的Java基于Spring框架的微... 目录一、环境搭建二、创建 Spring Boot 项目三、引入二维码生成依赖四、编写二维码生成代码五

使用Python和PaddleOCR实现图文识别的代码和步骤

《使用Python和PaddleOCR实现图文识别的代码和步骤》在当今数字化时代,图文识别技术的应用越来越广泛,如文档数字化、信息提取等,PaddleOCR是百度开源的一款强大的OCR工具包,它集成了... 目录一、引言二、环境准备2.1 安装 python2.2 安装 PaddlePaddle2.3 安装

Python datetime 模块概述及应用场景

《Pythondatetime模块概述及应用场景》Python的datetime模块是标准库中用于处理日期和时间的核心模块,本文给大家介绍Pythondatetime模块概述及应用场景,感兴趣的朋... 目录一、python datetime 模块概述二、datetime 模块核心类解析三、日期时间格式化与

Python如何调用指定路径的模块

《Python如何调用指定路径的模块》要在Python中调用指定路径的模块,可以使用sys.path.append,importlib.util.spec_from_file_location和exe... 目录一、sys.path.append() 方法1. 方法简介2. 使用示例3. 注意事项二、imp

SpringBoot中四种AOP实战应用场景及代码实现

《SpringBoot中四种AOP实战应用场景及代码实现》面向切面编程(AOP)是Spring框架的核心功能之一,它通过预编译和运行期动态代理实现程序功能的统一维护,在SpringBoot应用中,AO... 目录引言场景一:日志记录与性能监控业务需求实现方案使用示例扩展:MDC实现请求跟踪场景二:权限控制与

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

Python的time模块一些常用功能(各种与时间相关的函数)

《Python的time模块一些常用功能(各种与时间相关的函数)》Python的time模块提供了各种与时间相关的函数,包括获取当前时间、处理时间间隔、执行时间测量等,:本文主要介绍Python的... 目录1. 获取当前时间2. 时间格式化3. 延时执行4. 时间戳运算5. 计算代码执行时间6. 转换为指