优化日志

This commit is contained in:
COOL 2024-07-02 16:42:22 +08:00
parent 6a34c86fb8
commit 82e161ef38
5 changed files with 1 additions and 32 deletions

Binary file not shown.

View File

@ -23,29 +23,6 @@ export class Utils {
);
}
/**
* IP获得请求地址
* @param ip IP地址
*/
async getIpAddr(ctx: Context, ip?: string | string[]) {
try {
if (!ip) {
ip = await this.getReqIP(ctx);
}
const bst = new ipdb.BaseStation(`${this.baseDir}/comm/ipipfree.ipdb`);
const result = bst.findInfo(ip, 'CN');
const addArr: any = [];
if (result) {
addArr.push(result.countryName);
addArr.push(result.regionName);
addArr.push(result.cityName);
return _.uniq(addArr).join('');
}
} catch (err) {
return '无法获取地址信息';
}
}
/**
*
* @param obj

View File

@ -17,7 +17,7 @@ import { BaseSysLogService } from '../../../service/sys/log';
url: ['add'],
},
pageQueryOp: {
keyWordLikeFields: ['b.name', 'a.ipAddr'],
keyWordLikeFields: ['b.name', 'a.action', 'a.ip'],
select: ['a.*', 'b.name'],
join: [
{

View File

@ -18,10 +18,6 @@ export class BaseSysLogEntity extends BaseEntity {
@Column({ comment: 'ip', nullable: true })
ip: string;
@Index()
@Column({ comment: 'ip地址', nullable: true, length: 50 })
ipAddr: string;
@Column({ comment: '参数', nullable: true, type: 'json' })
params: string;
}

View File

@ -37,10 +37,6 @@ export class BaseSysLogService extends BaseService {
const sysLog = new BaseSysLogEntity();
sysLog.userId = userId;
sysLog.ip = typeof ip === 'string' ? ip : ip.join(',');
const ipAddrArr = [];
for (const e of sysLog.ip.split(','))
ipAddrArr.push(await this.utils.getIpAddr(context, e));
sysLog.ipAddr = ipAddrArr.join(',');
sysLog.action = url.split('?')[0];
sysLog.params = params;
await this.baseSysLogEntity.insert(sysLog);