当前位置:网站首页>M write log to text
M write log to text
2022-08-07 03:38:00 【Walk in loosing】
之前MWrite logs are in the table andgloble里.I haven't tried to write to the log file.According to the help package, there is a write log method.
Find helpFile类
查帮助MHow to get runningOS
Implement the write log method
/// 写日志到文件中
/// w ##Class(LIS.WS.DHCLISServiceBase).WriteLog("I am Zhang Shan")
/// logStr:log string
/// logpath:日志路径,If it is not given, it will be controlled internally
ClassMethod WriteLog(logStr, logpath)
{
s logStr=$g(logStr)
s logpath=$g(logpath)
s IsLinux=1
i ##class(%SYSTEM.Version).GetOS()="Windows" s IsLinux=0
//默认路径
i '$l(logpath) d
.i IsLinux=0 d
..s logpath="D:\cachelog\"
.e d
..s logpath="/"
i '$d(^LogFileIndex) s ^LogFileIndex=0
s index=$g(^LogFileIndex)
s logName=logpath_"Log"_index_".txt"
s file=##class(%File).%New(logName)
//存在就追加
i ##class(%File).Exists(logName) d
.Do file.Open("AWS:/SHARED")
//不存在就新建
e d
.Do file.Open("WSN:/SHARED")
//日志头
s HeadStr=$zd($h,8)_" ["_$zt($p($h,",",2))_"] "
//写日志
d file.WriteLine($zcvt(HeadStr_logStr,"O","UTF8"))
//判断大小
s fileSize=file.Size
//If the file is too large, replace it
i fileSize>(1024*1000) d
.s ^LogFileIndex=^LogFileIndex+1
d file.Close()
q ""
}
测试
/// w ##Class(LIS.WS.DHCLISServiceBase).TT()
ClassMethod TT()
{
f i=1:1:100000000 d
.d ##Class(LIS.WS.DHCLISServiceBase).WriteLog("I am Zhang Shan"_i)
}

边栏推荐
猜你喜欢

'Wed Aug 03 19:48:03 +0800 2022'这种字符串,怎么转成时间格式年月日

Scala object class basic grammar explanation

方舟生存进化游戏设置怎么调设置推荐

小程序容器在一体化在线政务服务平台中的应用

损失函数_相似度计算_距离计算

记录WPF的技巧(二)16-30

水质自动监测和视频监控,巩固提升饮用水安全保障水平

JSP第一篇 -----JSP浅聊EL表达式第一篇: 基础操作,以及域搜索顺序以及EL隐式对象

82-FastDFS detailed explanation

Wireless Video Surveillance of Construction Site Industrial Grade Wireless Router Application
随机推荐
OAuth2的定义和运行流程
POST request
wpf中TreeView的滚动条
权重的初始化总结
Hessian 序列化、反序列化
Wonderful Review|Cloud Native Meetup Guangzhou Station
Parse the structure inside the wpf control
golang服务器代理
LVS load balancing cluster
1008: series summation
微信小程序获取页面自定义属性值
关于DevExpress的设置记录
82-FastDFS detailed explanation
406. According to height reconstruction queue - sort + dynamic programming
LVS-DR
The difference between target and currentTarget in WeChat applet
c#多线程同步执行
我们来聊聊锁升级吧
微信小程序中rpx
Some basic concepts and methods of proxy ip (updating...)