Skip to content

Commit

Permalink
Updating tests, transport callback update
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg committed Apr 18, 2024
1 parent a82656c commit 3a2256d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
10 changes: 4 additions & 6 deletions packages/winston-transport/src/OpenTelemetryTransportV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ export class OpenTelemetryTransportV3 extends TransportStream {
this._logger = logs.getLogger('@opentelemetry/winston-transport', VERSION);
}

public override log(info: any, next: () => void) {
public override log(info: any, callback: () => void) {
try {
emitLogRecord(info, this._logger);
} catch (error) {
this.emit('warn', error);
}
setImmediate(() => {
this.emit('logged', info);
});
if (next) {
setImmediate(next);
this.emit('logged', info);
if (callback) {
callback();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,29 +395,51 @@ describe('WinstonInstrumentation', () => {
if (!isWinston2) {
instrumentation.setConfig({
disableLogSending: false,
logSeverity: SeverityNumber.ERROR,
logSeverity: SeverityNumber.DEBUG,
});
initLogger(LevelsType.npm);
logger.log('silly', 'silly');
logger.log('debug', 'debug');
logger.log('verbose', 'verbose');
logger.log('http', 'http');
logger.log('info', 'info');
logger.log('warn', 'warn');
logger.log('error', 'error');
const logRecords = memoryLogExporter.getFinishedLogRecords();
assert.strictEqual(logRecords.length, 1);
assert.strictEqual(logRecords[0].body, 'error');
assert.strictEqual(logRecords.length, 6);
assert.strictEqual(logRecords[0].body, 'debug');
assert.strictEqual(logRecords[1].body, 'verbose');
assert.strictEqual(logRecords[2].body, 'http');
assert.strictEqual(logRecords[3].body, 'info');
assert.strictEqual(logRecords[4].body, 'warn');
assert.strictEqual(logRecords[5].body, 'error');
}
});

it('cli levels', () => {
if (!isWinston2) {
instrumentation.setConfig({
disableLogSending: false,
logSeverity: SeverityNumber.WARN,
logSeverity: SeverityNumber.INFO,
});
initLogger(LevelsType.cli);
logger.log('silly', 'silly');
logger.log('input', 'input');
logger.log('verbose', 'verbose');
logger.log('prompt', 'prompt');
logger.log('debug', 'debug');
logger.log('info', 'info');
logger.log('data', 'data');
logger.log('help', 'help');
logger.log('warn', 'warn');
logger.log('error', 'error');
const logRecords = memoryLogExporter.getFinishedLogRecords();
assert.strictEqual(logRecords.length, 1);
assert.strictEqual(logRecords[0].body, 'warn');
assert.strictEqual(logRecords.length, 5);
assert.strictEqual(logRecords[0].body, 'info');
assert.strictEqual(logRecords[1].body, 'data');
assert.strictEqual(logRecords[2].body, 'help');
assert.strictEqual(logRecords[3].body, 'warn');
assert.strictEqual(logRecords[4].body, 'error');
}
});

Expand All @@ -428,11 +450,21 @@ describe('WinstonInstrumentation', () => {
logSeverity: SeverityNumber.WARN,
});
initLogger(LevelsType.syslog);
logger.log('debug', 'debug');
logger.log('info', 'info');
logger.log('notice', 'notice');
logger.log('warning', 'warning');
logger.log('error', 'error');
logger.log('crit', 'crit');
logger.log('alert', 'alert');
logger.log('emerg', 'emerg');
const logRecords = memoryLogExporter.getFinishedLogRecords();
assert.strictEqual(logRecords.length, 1);
assert.strictEqual(logRecords[0].body, 'emerg');
assert.strictEqual(logRecords.length, 5);
assert.strictEqual(logRecords[0].body, 'warning');
assert.strictEqual(logRecords[1].body, 'error');
assert.strictEqual(logRecords[2].body, 'crit');
assert.strictEqual(logRecords[3].body, 'alert');
assert.strictEqual(logRecords[4].body, 'emerg');
}
});
});
Expand Down

0 comments on commit 3a2256d

Please sign in to comment.