首页 > 其他分享 >ssts-hospital-web-master项目实战记录十四:项目迁移-模块实现(log-local)

ssts-hospital-web-master项目实战记录十四:项目迁移-模块实现(log-local)

时间:2024-02-25 23:22:17浏览次数:14  
标签:info web const log LogTerminalInfoDir ssts framework string

记录时间:2024-02-25

一、log-local模块实现

framework/config/index.ts

//终端日志文件配置 const LogTerminalInfoDir = 'D:\\LogInfo\\LogTerminalInfo\\' const LogTerminalInfoFileNamePrefix = 'LogTerminalInfo'
//错误页面快照文件配置 const LogErrorPageSnapshotFileDir = 'D:\\LogInfo\\LogErrorPageSnapShot\\'
export {   LogTerminalInfoDir,   LogTerminalInfoFileNamePrefix,   LogErrorPageSnapshotFileDir }  

framework/utils/log-local.ts

import { FileSystemObjectImpl } from '@/framework/file-system-object' import hydate from '@/utils/date-format' import { AjaxObject } from '@/framework/types' import {   allProps,   CreateSnapshotFileName,   GetPageInfo,   GetControlsInfo } from '@/framework/page-info' import {   LogTerminalInfoDir,   LogTerminalInfoFileNamePrefix,   LogErrorPageSnapshotFileDir } from '@/framework/config'
//创建多层文件夹(通过服务接口记录日志时,不需要创建文件夹) function CreateFolder(fso: FileSystemObjectImpl, path: string): void {   path = path.replace(/\\/g, '/')
  // 如果文件夹已经存在,则直接返回   fso.FolderExists(path).then(async (exists) => {     if (exists) {       return     } else {       // 创建文件夹       try {         fso.CreateFolder(path)       } catch (error) {         console.error(`Failed to create folder at path: ${path}`, error)       }     }   }) }
//记录日志文件 const LogInfo = function (folder: string, filename: string, log: string) {   const fso = new FileSystemObjectImpl()   if (filename.indexOf(folder) == -1) {     filename = `${folder}\\${filename}`   }   filename = filename.replace(/\\/g, '/')
  const openFile = fso.OpenTextFile(filename, 8, true)   openFile.WriteLine(log)   openFile.Close() }
//记录自定义日志文件 //forder:文件夹(如:D:\\LogInfo\\LogTerminalInfo\\) //fileNamePrefix:文件名前缀(如:LogTerminalInfo) //info:日志信息 //deviceName:设备名称 //symbol:符号(控件页符号、事件符号、对象符号、错误符号) const LogCustomInfo = function (   forder: string,   fileNamePrefix: string,   info: string,   deviceName?: string | null,   symbol?: string | null ) {   const now = new Date()   const folder = forder + hydate(now).format('YYYY-MM') //月份作为文件夹   const file = `${fileNamePrefix}${hydate(now).format('YYYY-MM-DD')}.txt` //日作为文件名   const filename = `${folder}\\${file}` //完整文件名
  let log = info   if (     typeof deviceName != 'undefined' &&     deviceName != null &&     deviceName != ''   ) {     log = `[${deviceName}]${info}`   } else if (typeof symbol != 'undefined' && symbol != null && symbol != '') {     log = `[${symbol}]${info}`   }   //左补毫秒级时间   log = `${hydate(now).format('YYYY-MM-DD HH:mm:ss.SSS')} ${log}`
  LogInfo(folder, filename, log) }
//记录终端日志信息 const LogTerminalInfo = function (info: string) {   LogCustomInfo(LogTerminalInfoDir, LogTerminalInfoFileNamePrefix, info) }
//记录Device页面日志 const LogDevicePageInfo = function (info: string) {   return LogCustomInfo(     LogTerminalInfoDir,     LogTerminalInfoFileNamePrefix,     info,     null,     '■'   ) }
//记录错误页面快照文件 //格式:时间-【业务流水号】-页面名-【错误信息:】-【行号:】 const LogErrorPageSnapshotFile = function (   fileName: string,   fileContent: string,   businessTrace: string | null ) {   const now = new Date()   const folder = LogErrorPageSnapshotFileDir + hydate(now).format('YYYY-MM') //月份作为文件夹   const file = `${hydate(now).format('YYYYMMDDHHmmss')}-【${businessTrace}】-${fileName}.txt`   const filename = `${folder}\\${file}` //完整文件名
  LogInfo(folder, filename, fileContent) }
//记录对象日志 const LogObjectInfo = function (   objName: string,   obj: object,   businessTrace: string | null ) {   const objPrpos = allProps(obj)
  //Url路径   const href = decodeURIComponent(window.location.href)   const pageInfo = `${businessTrace}】【数据对象】-【${href}】${objName}\r\n`
  LogTerminalInfo(pageInfo + objPrpos) }
//记录Ajax成功事件日志 const LogTerminalAjaxSuccessInfo = function (   thisAjax: AjaxObject,   result: any ) {   const info = `     ${thisAjax.url}     ${thisAjax.data}     result: ${result}   `
  LogCustomInfo(     LogTerminalInfoDir,     LogTerminalInfoFileNamePrefix,     info,     null,     '★AjaxSuccess★'   ) }
//记录Ajax错误事件日志 const LogTerminalAjaxErrorInfo = (   thisAjax: {     url: string     data: any   },   XMLHttpRequest: {     readyState: number     responseText: string     status: number     statusText: string   },   textStatus: string,   errorThrown: any ) => {   // 使用模板字符串简化字符串拼接   const info = `     URL: ${thisAjax.url}     Data: ${JSON.stringify(thisAjax.data)}     XMLHttpRequest.readyState: ${XMLHttpRequest.readyState}     XMLHttpRequest.responseText: ${XMLHttpRequest.responseText}     XMLHttpRequest.status: ${XMLHttpRequest.status}     XMLHttpRequest.statusText: ${XMLHttpRequest.statusText}     textStatus: ${textStatus}     errorThrown: ${errorThrown}   `
  // 调用 LogCustomInfo 函数记录错误信息   LogCustomInfo(     LogTerminalInfoDir,     LogTerminalInfoFileNamePrefix,     info,     null,     '★AjaxError★'   ) }
export {   allProps,   CreateSnapshotFileName,   GetPageInfo,   GetControlsInfo,   CreateFolder,   LogInfo,   LogCustomInfo,   LogDevicePageInfo,   LogErrorPageSnapshotFile,   LogObjectInfo,   LogTerminalInfo,   LogTerminalAjaxSuccessInfo,   LogTerminalAjaxErrorInfo }  

二、调用示例

test-framework-log-local.vue

<script setup lang="ts"> import { onMounted } from 'vue' import hydate from '@/utils/date-format' import { FileSystemObjectImpl } from '@/framework/file-system-object' import { CreateSnapshotFileName } from '@/framework/utils/log-local' import { CreateFolder, LogInfo, LogCustomInfo, LogDevicePageInfo, LogErrorPageSnapshotFile, LogObjectInfo, LogTerminalInfo } from '@/framework/utils/log-local' import { LogTerminalInfoDir, LogTerminalInfoFileNamePrefix } from '@/framework/config';
const TestLogLocal = function () {   console.log('TestLogLocal begin')
  const LogTestDir = 'D:\\LogInfo\\LogTest\\2024-02\\'   console.log('LogTestDir:', LogTestDir)   const fso = new FileSystemObjectImpl()   CreateFolder(fso, LogTestDir)
  const LogTestFileName = `${LogTestDir}log.txt`   LogInfo(LogTestDir, LogTestFileName, `${hydate(new Date()).format('YYYY-MM-DD HH:mm:ss.SSS')}`)
  console.log('LogTerminalInfoDir:', LogTerminalInfoDir, 'LogTerminalInfoFileNamePrefix:', LogTerminalInfoFileNamePrefix)   LogCustomInfo(LogTerminalInfoDir, LogTerminalInfoFileNamePrefix, `${hydate(new Date()).format('YYYY-MM-DD HH:mm:ss.SSS')}`, null, 'Test')
  LogDevicePageInfo('test')
  const businessTrace = null   const info = {     errorMessage: 'test',     lineNumber: 1,     href: `http://localhost:19004/WebAdapter_AdapterTest.html`   }
  const snapshotInfoInline = `${info.href}-【${info.errorMessage}】-【行号:${info.lineNumber}】`   const snapshotFileName = CreateSnapshotFileName(snapshotInfoInline)   LogErrorPageSnapshotFile(snapshotFileName, 'test', businessTrace)
  const objTest = { 'TerminalIp': '192.168.1.100', 'TerminalName': 'test' }   console.log('objTest:', objTest)   LogObjectInfo('objTest', objTest, businessTrace)
  LogTerminalInfo('test')
  console.log('TestLogLocal end') }
onMounted(() => {   console.log('test-framework.vue', 'mounted')
  TestLogLocal() })
</script>
<template>   <div>     <title>测试框架</title>     <input id="inputTest" type="text" value="this is a test input." />     <span id="spanTest">this is a test span.</span>   </div> </template>
<style scoped></style>  

三、运行测试

 

翻译

搜索

复制

<iframe></iframe>

标签:info,web,const,log,LogTerminalInfoDir,ssts,framework,string
From: https://www.cnblogs.com/lizhigang/p/18033340

相关文章

  • Docker安装mariadb数据库与web管理工具phpmyadmin
    安装mariadb数据库获取指定版本的mariadb数据库docker镜像使用dockersearchmariadb搜索相关镜像;MacBook-Pro:~chenxiaolong$dockersearchmariadbNAMEDESCRIPTIONSTARSOFFICIALAUTOMATEDmar......
  • .Net 6 WebAPI 使用JWT进行 授权认证配置
    .Net6WebAPI使用JWT进行授权认证1、安装组件(Nuget)Microsoft.AspNetCore.Authentication.JwtBearer2、Program.cs配置//授权认证(使用JWT)builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(o=>{//私钥varsecretByte=Enco......
  • EasyBlogImageForTypora 上传报错,重新配置
    EasyBlogImageForTypora上传报错,重新配置先前使用EasyBlogImageForTypora上传图片正常,但是最近报错了(先前没弄明白报错原因,下载了项目代码,手动进行了调试)。上传图片接口服务器方法如下:查看VS监视结果发现:此时突然发现UserName与Password应该保持一致,是WebLogApi的参数,于......
  • ssts-hospital-web-master项目实战记录十四:项目迁移-模块实现(file-system-object:FileS
    记录时间:2024-02-25一、准备工作【使用“文心一言”搜索使用ts实现类模块】在TypeScript中,类可以作为模块的一部分被导出,这样其他模块就可以导入并使用这些类。以下是如何使用TypeScript实现类模块的基本步骤:步骤1:定义类模块首先,在一个TypeScript文件中定义一个或多个......
  • Verilog基本语法知识
    define就是一个宏定义define原变量新的值或者名称或表达式再使用的时候可以原变量代替undef是取消定义宏`undef原变量即可完成取消`include"文件名.V"这样可以将文件名.V的全部内容赋值并插入到这条语句所出现的地方,并且在编译中将包含了文件名.V的文件作为源文件进......
  • Taurus.MVC WebMVC 入门开发教程1:框架下载环境配置与运行
    前言:之前有网友说Mvc系列的教程对新手不友好,因此补充新手入门系列教程。在开始使用Taurus.Mvc 进行Web应用开发之前,建议可以观摩一下之前的文章:WebAPI系列教程因为两者的教程,有相通的部分,唯一的差别部分,在于Web应用涉及到UI界面。本系列的目录大纲为:Taurus.MVCWebMVC......
  • 【深度学习】Logistic回归算法和向量化编程。全md文档笔记(代码文档已分享)
    本系列文章md笔记(已分享)主要讨论深度学习相关知识。可以让大家熟练掌握机器学习基础,如分类、回归(含代码),熟练掌握numpy,pandas,sklearn等框架使用。在算法上,掌握神经网络的数学原理,手动实现简单的神经网络结构,在应用上熟练掌握TensorFlow框架使用,掌握神经网络图像相关案例。具体......
  • ../inst/include/Eigen/src/Core/MathFunctions.h:487:16: error: no member named 'R
    Asmentionedin conda-forge/r-base-feedstock#163(comment),IsuccessfullyinstalledsctransforminMacsiliconM1Maxbyfirstrun exportPKG_CPPFLAGS="-DHAVE_WORKING_LOG1P intheterminalandtheninstallthepackageinR.......
  • oracle指定控制文件启动 ORA-00205: error in identifying control file, check aler
    SQL>startupORACLEinstancestarted.TotalSystemGlobalArea1068937216bytesFixedSize2220200bytesVariableSize708841304bytesDatabaseBuffers352321536bytesRedoBuffers5554176bytesORA-00205:......
  • ssts-hospital-web-master项目实战记录十三:项目迁移-架构设计(前台管理)
    记录时间:2024-02-24前台管理 CashTradeClean.html CashTradeDetails.html CashTradeSettle.html DeviceTest.html GoodsManage.html login.html Main.html ReceiptReprint.html SystemManage.html翻译搜索复制......