thinkjs / thinkjs/thinkjs

如何直接调用log4js

Open
#1,019 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.3k
Forks
614
PR merge metrics
No merged PRs in 30d

Description

DESC

thinkjs提供的logger级别太少

    TRACE: new Level(5000, 'TRACE', 'blue'),
    DEBUG: new Level(10000, 'DEBUG', 'cyan'),
    INFO: new Level(20000, 'INFO', 'green'),
    WARN: new Level(30000, 'WARN', 'yellow'),
    ERROR: new Level(40000, 'ERROR', 'red'),
    FATAL: new Level(50000, 'FATAL', 'magenta'),
    MARK: new Level(9007199254740992, 'MARK', 'grey'), // 2^53
    OFF: new Level(Number.MAX_VALUE, 'OFF', 'grey')

另外category也被弄没了

constructor(config) {
    this[_logger] = {};
    const logConfig = this.formatConfig(config);
    this.setLogger(logConfig);
  }
...
setLogger(config, category) {
    this.configure(config);
    this[_logger] = log4js.getLogger(category);
  }

所以想直接调用Log4js。

在worker中直接调用如下代码,并不能写入到文件cheese.log中:

const log4js = require('log4js');
log4js.configure({
  appenders: { cheese: { type: 'file', filename: 'cheese.log' } },
  categories: { default: { appenders: ['cheese'], level: 'error' } }
});

const logger = log4js.getLogger('cheese');
logger.trace('Entering cheese testing');
logger.debug('Got cheese.');
logger.info('Cheese is Gouda.');
logger.warn('Cheese is quite smelly.');
logger.error('Cheese is too ripe!');
logger.fatal('Cheese was breeding ground for listeria.');
ENV

OS Platform:
mac
Node.js Version:
8.9.1
ThinkJS Version:
3.0
think-cli@1.0.13

code
error message
more description

// your detail description

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the worker example with the shown log4js configuration and inspect the logger setup around the provided constructor and setLogger snippets. Determine why the configured logger does not write cheese.log and clarify whether direct log4js access should preserve categories and levels; done means a documented or tested working path for worker logging.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
backend, observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.