xiaoju-survey/server/src/logger/util.ts

16 lines
371 B
TypeScript
Raw Normal View History

2024-01-30 14:19:45 +00:00
import { customAlphabet } from 'nanoid';
const traceIdAlphabet = 'abcdef0123456789';
let count = 0;
const getCountStr = () => {
count++;
return count.toString().padStart(8, '0');
};
const getRandom = customAlphabet(traceIdAlphabet, 10);
export const genTraceId = (): string => {
return getRandom() + Math.round(Date.now() / 1000).toString() + getCountStr();
};