eggjs / egg-logger
Showing 1 of 4 files from the diff.

@@ -23,6 +23,7 @@
Loading
23 23
  agentLogName: '',
24 24
  errorLogName: '',
25 25
  concentrateError: 'duplicate',
26 +
  concentrateErrorLoggerName: 'errorLogger',
26 27
};
27 28
28 29
/**
@@ -49,7 +50,8 @@
Loading
49 50
   *   - {String} agentLogName - egg agent file logger name
50 51
   *   - {String} errorLogName - err common error logger name
51 52
   *   - {String} eol - end of line char
52 -
   *   - {String} [concentrateError = duplicate] - whether write error logger to common-error.log, `duplicate` / `redirect` / `ignore`
53 +
   *   - {String} [concentrateError = duplicate] - whether write error logger to `concentrateErrorLoggerName` logger, `duplicate` / `redirect` / `ignore`
54 +
   *   - {String} [concentrateErrorLoggerName = errorLogger] - concentrate logger name
53 55
   * - customLogger
54 56
   */
55 57
  constructor(config) {
@@ -71,32 +73,39 @@
Loading
71 73
    }));
72 74
    this.set('errorLogger', errorLogger);
73 75
76 +
    let coreLogger;
77 +
    let logger;
74 78
    if (loggerConfig.type === 'agent') {
75 -
      const logger = new Logger(utils.assign({}, loggerConfig, {
79 +
      logger = new Logger(utils.assign({}, loggerConfig, {
76 80
        file: loggerConfig.agentLogName,
77 81
      }));
78 -
      this.set('logger', logger);
79 82
80 -
      const coreLogger = new Logger(utils.assign({}, loggerConfig, loggerConfig.coreLogger, {
83 +
      coreLogger = new Logger(utils.assign({}, loggerConfig, loggerConfig.coreLogger, {
81 84
        file: loggerConfig.agentLogName,
82 85
      }));
83 -
      this.set('coreLogger', coreLogger);
84 86
    } else {
85 -
      const logger = new Logger(utils.assign({}, loggerConfig, {
87 +
      logger = new Logger(utils.assign({}, loggerConfig, {
86 88
        file: loggerConfig.appLogName,
87 89
      }));
88 -
      this.set('logger', logger);
89 90
90 -
      const coreLogger = new Logger(utils.assign({}, loggerConfig, loggerConfig.coreLogger, {
91 +
      coreLogger = new Logger(utils.assign({}, loggerConfig, loggerConfig.coreLogger, {
91 92
        file: loggerConfig.coreLogName,
92 93
      }));
93 -
      this.set('coreLogger', coreLogger);
94 94
    }
95 +
    this.set('logger', logger);
96 +
    this.set('coreLogger', coreLogger);
95 97
96 98
    for (const name in customLoggerConfig) {
97 99
      const logger = new CustomLogger(utils.assign({}, loggerConfig, customLoggerConfig[name]));
98 100
      this.set(name, logger);
99 101
    }
102 +
103 +
    // setConcentrateError at the end
104 +
    this.setConcentrateError('logger', logger);
105 +
    this.setConcentrateError('coreLogger', coreLogger);
106 +
    for (const name in customLoggerConfig) {
107 +
      this.setConcentrateError(name, this.get(name));
108 +
    }
100 109
  }
101 110
102 111
  /**
@@ -124,14 +133,22 @@
Loading
124 133
      return;
125 134
    }
126 135
136 +
    this[name] = logger;
137 +
    super.set(name, logger);
138 +
  }
139 +
140 +
  setConcentrateError(name, logger) {
127 141
    // redirect ERROR log to errorLogger, except errorLogger itself
128 142
    if (name !== 'errorLogger') {
143 +
      const concentrateLogger = this.get(logger.options.concentrateErrorLoggerName);
144 +
      if (!concentrateLogger) return;
145 +
129 146
      switch (logger.options.concentrateError) {
130 147
        case 'duplicate':
131 -
          logger.duplicate('error', this.errorLogger, { excludes: [ 'console' ] });
148 +
          logger.duplicate('error', concentrateLogger, { excludes: [ 'console' ] });
132 149
          break;
133 150
        case 'redirect':
134 -
          logger.redirect('error', this.errorLogger);
151 +
          logger.redirect('error', concentrateLogger);
135 152
          break;
136 153
        case 'ignore':
137 154
          break;
@@ -139,8 +156,6 @@
Loading
139 156
          break;
140 157
      }
141 158
    }
142 -
    this[name] = logger;
143 -
    super.set(name, logger);
144 159
  }
145 160
146 161
}
Files Coverage
lib 97.36%
index.js 100.00%
Project Totals (14 files) 97.43%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading