Skip to content

Commit

Permalink
feat: log (#16)
Browse files Browse the repository at this point in the history
* feat: log

* chore: npm&pnpm
  • Loading branch information
txp1035 authored Jul 14, 2022
1 parent 414ca19 commit 5356fef
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
registry=https://registry.npmjs.org/
registry=https://registry.npmmirror.com
strict-peer-dependencies=false
8 changes: 7 additions & 1 deletion packages/auto-command/src/translate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,10 @@ async function core({
}
signale.timeEnd('translate');
}
export default core;
export default async (options: TranslateConfig) => {
try {
await core(options);
} catch (error) {
utils.node.logger.error(error);
}
};
8 changes: 6 additions & 2 deletions packages/auto-command/src/translate/translate-i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ export default async function i18n(content: string, options: I18nOptions) {
if (options.language.from) {
obj.language.from = handelCode(
options.language.from,
options.translatorType,
options.translatorType || 'youdao',
options.separator,
);
}
if (options.language.to) {
obj.language.to = handelCode(options.language.to, options.translatorType, options.separator);
obj.language.to = handelCode(
options.language.to,
options.translatorType || 'youdao',
options.separator,
);
}
const res = await translate(content, obj);
return res;
Expand Down
4 changes: 3 additions & 1 deletion packages/txp-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
},
"dependencies": {
"chalk": "^5.0.1",
"dayjs": "^1.11.3",
"fs-extra": "^10.1.0",
"pino": "^8.1.0"
"pino": "^8.1.0",
"pino-pretty": "^8.1.0"
},
"authors": [
"tangxiaoping <[email protected]> (https://github.com/txp1035)"
Expand Down
9 changes: 5 additions & 4 deletions packages/txp-utils/src/node/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const customLevels = {
ready: 31,
event: 32,
wait: 55,
// 虽然这里设置了 debug 为 30,但日志中还是 20,符合预期
// 这里不加会不生成到 txp.log,transport 的 level 配置没有生效,原因不明
debug: 30,
};

let logger: Logger<{ customLevels: typeof customLevels }>;
Expand All @@ -23,13 +20,17 @@ function init() {
logger = pino(
{
customLevels,
level: 'debug',
},
pino.transport({
targets: [
{
target: require.resolve('pino/file'),
target: 'pino-pretty',
options: {
destination: loggerPath,
colorize: false,
translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l',
messageFormat: 'level: {level}、msg: {msg}',
},
level: 'trace',
},
Expand Down
105 changes: 96 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5356fef

Please sign in to comment.