Skip to content

Commit

Permalink
fix(logger): removing spaces from logger (#3334)
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloverdijk authored Aug 31, 2024
1 parent 72f4c9d commit 6c19429
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/middleware/logger/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@ describe('Logger by Middleware', () => {
const res = await app.request('http://localhost/empty')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(log.startsWith(' --> GET /empty \x1b[32m200\x1b[0m')).toBe(true)
expect(log.startsWith('--> GET /empty \x1b[32m200\x1b[0m')).toBe(true)
expect(log).toMatch(/m?s$/)
})

it('Log status 200 with small body', async () => {
const res = await app.request('http://localhost/short')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(log.startsWith(' --> GET /short \x1b[32m200\x1b[0m')).toBe(true)
expect(log.startsWith('--> GET /short \x1b[32m200\x1b[0m')).toBe(true)
expect(log).toMatch(/m?s$/)
})

it('Log status 200 with big body', async () => {
const res = await app.request('http://localhost/long')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(log.startsWith(' --> GET /long \x1b[32m200\x1b[0m')).toBe(true)
expect(log.startsWith('--> GET /long \x1b[32m200\x1b[0m')).toBe(true)
expect(log).toMatch(/m?s$/)
})

it('Time in seconds', async () => {
const res = await app.request('http://localhost/seconds')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(log.startsWith(' --> GET /seconds \x1b[32m200\x1b[0m')).toBe(true)
expect(log.startsWith('--> GET /seconds \x1b[32m200\x1b[0m')).toBe(true)
expect(log).toMatch(/1s/)
})

Expand All @@ -70,7 +70,7 @@ describe('Logger by Middleware', () => {
const res = await app.request('http://localhost/notfound')
expect(res).not.toBeNull()
expect(res.status).toBe(404)
expect(log.startsWith(' --> GET /notfound \x1b[33m404\x1b[0m')).toBe(true)
expect(log.startsWith('--> GET /notfound \x1b[33m404\x1b[0m')).toBe(true)
expect(log).toMatch(/m?s$/)
})
})
Expand Down Expand Up @@ -111,31 +111,31 @@ describe('Logger by Middleware in NO_COLOR', () => {
const res = await app.request('http://localhost/empty')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(log.startsWith(' --> GET /empty 200')).toBe(true)
expect(log.startsWith('--> GET /empty 200')).toBe(true)
expect(log).toMatch(/m?s$/)
})

it('Log status 200 with small body', async () => {
const res = await app.request('http://localhost/short')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(log.startsWith(' --> GET /short 200')).toBe(true)
expect(log.startsWith('--> GET /short 200')).toBe(true)
expect(log).toMatch(/m?s$/)
})

it('Log status 200 with big body', async () => {
const res = await app.request('http://localhost/long')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(log.startsWith(' --> GET /long 200')).toBe(true)
expect(log.startsWith('--> GET /long 200')).toBe(true)
expect(log).toMatch(/m?s$/)
})

it('Time in seconds', async () => {
const res = await app.request('http://localhost/seconds')
expect(res).not.toBeNull()
expect(res.status).toBe(200)
expect(log.startsWith(' --> GET /seconds 200')).toBe(true)
expect(log.startsWith('--> GET /seconds 200')).toBe(true)
expect(log).toMatch(/1s/)
})

Expand All @@ -147,7 +147,7 @@ describe('Logger by Middleware in NO_COLOR', () => {
const res = await app.request('http://localhost/notfound')
expect(res).not.toBeNull()
expect(res.status).toBe(404)
expect(log.startsWith(' --> GET /notfound 404')).toBe(true)
expect(log.startsWith('--> GET /notfound 404')).toBe(true)
expect(log).toMatch(/m?s$/)
})
})
4 changes: 2 additions & 2 deletions src/middleware/logger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function log(
) {
const out =
prefix === LogPrefix.Incoming
? ` ${prefix} ${method} ${path}`
: ` ${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`
? `${prefix} ${method} ${path}`
: `${prefix} ${method} ${path} ${colorStatus(status)} ${elapsed}`
fn(out)
}

Expand Down

0 comments on commit 6c19429

Please sign in to comment.