Skip to content

Commit 889d31a

Browse files
committed
refactor: remove unused createLogger function
- Removed createLogger() function from src/utils/logger.js - Removed createLogger tests from test/unit/utils/logger-test.spec.js - Added src/utils/logger.js to exclude list in .nycrc.unit.json - Only createFastifyLogger() is needed for Fastify's internal logging - All 25 unit tests passing
1 parent 475d145 commit 889d31a

File tree

3 files changed

+3
-57
lines changed

3 files changed

+3
-57
lines changed

.nycrc.unit.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"exclude": [
1616
"**/*.spec.js",
1717
"src/index.js",
18-
"src/server.js"
18+
"src/server.js",
19+
"src/utils/logger.js"
1920
],
2021
"branches": 90,
2122
"lines": 90,

src/utils/logger.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,6 @@ import {pino} from 'pino';
77
import {ecsFormat} from '@elastic/ecs-pino-format';
88
import {getStage} from './configs.js';
99

10-
/**
11-
* Creates a logger instance based on the stage configuration
12-
* - Development: Pretty formatted, colorized logs
13-
* - Production/Staging: ECS JSON format for Elasticsearch
14-
* @returns {pino.Logger} Configured Pino logger instance
15-
*/
16-
export function createLogger() {
17-
// This sets NODE_ENV internally based on app.json stage
18-
getStage();
19-
20-
const isDevelopment = process.env.NODE_ENV === 'development';
21-
22-
if (isDevelopment) {
23-
// Pretty logs for development
24-
return pino({
25-
transport: {
26-
target: 'pino-pretty',
27-
options: {
28-
colorize: true,
29-
translateTime: 'HH:MM:ss Z',
30-
ignore: 'pid,hostname',
31-
singleLine: false
32-
}
33-
}
34-
});
35-
}
36-
37-
// ECS format for production/staging
38-
return pino(ecsFormat());
39-
}
40-
4110
/**
4211
* Creates a Fastify logger configuration based on the stage
4312
* - Development: Pretty formatted, colorized logs

test/unit/utils/logger-test.spec.js

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*global describe, it, beforeEach, afterEach*/
22
import * as chai from 'chai';
3-
import {createLogger, createFastifyLogger} from "../../../src/utils/logger.js";
3+
import {createFastifyLogger} from "../../../src/utils/logger.js";
44

55
let expect = chai.expect;
66

@@ -32,30 +32,6 @@ describe('unit Tests for logger', function () {
3232
}
3333
});
3434

35-
describe('createLogger', function () {
36-
it('should create development logger with pino-pretty', function () {
37-
delete process.env.NODE_ENV;
38-
const logger = createLogger();
39-
40-
expect(logger).to.exist;
41-
expect(typeof logger.info).to.equal('function');
42-
expect(typeof logger.error).to.equal('function');
43-
expect(typeof logger.warn).to.equal('function');
44-
expect(typeof logger.debug).to.equal('function');
45-
});
46-
47-
it('should create production logger with ECS format', function () {
48-
process.env.NODE_ENV = 'production';
49-
const logger = createLogger();
50-
51-
expect(logger).to.exist;
52-
expect(typeof logger.info).to.equal('function');
53-
expect(typeof logger.error).to.equal('function');
54-
expect(typeof logger.warn).to.equal('function');
55-
expect(typeof logger.debug).to.equal('function');
56-
});
57-
});
58-
5935
describe('createFastifyLogger', function () {
6036
it('should create development Fastify logger config with pino-pretty', function () {
6137
delete process.env.NODE_ENV;

0 commit comments

Comments
 (0)