@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
42 lines • 1.85 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
import 'sinon-chai';
import sinon from 'sinon';
import { expect } from 'chai';
import { describe, it, afterEach, beforeEach } from 'mocha';
import { SoloPinoLogger } from '../../../src/core/logging/solo-pino-logger.js';
describe('Logging', () => {
let logger;
let errorSpy;
let warnSpy;
let infoSpy;
let debugSpy;
let spyByLevel;
beforeEach(() => {
logger = new SoloPinoLogger('debug', false);
const pinoImpl = logger.pinoLogger;
errorSpy = sinon.spy(pinoImpl, 'error');
warnSpy = sinon.spy(pinoImpl, 'warn');
infoSpy = sinon.spy(pinoImpl, 'info');
debugSpy = sinon.spy(pinoImpl, 'debug');
spyByLevel = { error: errorSpy, warn: warnSpy, info: infoSpy, debug: debugSpy };
});
// Cleanup after each test
afterEach(() => sinon.restore());
it('should log at correct severity with traceId in meta', () => {
expect(logger).to.be.instanceof(SoloPinoLogger);
expect(logger).to.be.not.undefined;
// Grab the active traceId from the logger’s meta
const meta = logger.prepMeta();
const { traceId } = meta;
expect(traceId).to.be.a('string');
logger.error('Error log');
expect(spyByLevel.error).to.have.been.calledWithMatch(sinon.match.has('traceId', traceId), 'Error log');
logger.warn('Warn log');
expect(spyByLevel.warn).to.have.been.calledWithMatch(sinon.match.has('traceId', traceId), 'Warn log');
logger.info('Info log');
expect(spyByLevel.info).to.have.been.calledWithMatch(sinon.match.has('traceId', traceId), 'Info log');
logger.debug('Debug log');
expect(spyByLevel.debug).to.have.been.calledWithMatch(sinon.match.has('traceId', traceId), 'Debug log');
});
});
//# sourceMappingURL=logging.test.js.map