Skip to content

Commit

Permalink
Fix log output in acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwynne committed Mar 4, 2021
1 parent 25d0e7f commit 8a75b20
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/acceptance-tests/src/step_definitions/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Then(
)

Then('the repo should have been fetched', async function (this: World) {
// TODO: resolve duplication with the "fetched n times" step below
await promiseThat(
new Promise<void>((received) =>
this.domainEvents.on('repo.fetched', (event) => event.repoId.equals(this.repoId) && received())
Expand Down
8 changes: 5 additions & 3 deletions packages/acceptance-tests/src/support/abilities/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { dirSync } from 'tmp'

import { LaBoîte } from 'git-en-boite-app'
import { World } from '../world'
import { setUpLogger } from 'git-en-boite-logging'
const config = createConfig()
console.log('Starting acceptance tests with config:\n', JSON.stringify(config, null, 2))

Before(async function (this: World) {
this.domainEvents = new EventEmitter()
const config = createConfig()
this.log = setUpLogger({}, config.logger)
const gitReposPath = dirSync().name
const repoIndex = new InventoryOfReposOnDisk(gitReposPath, new DirectLocalClones(), this.domainEvents)
const log = () => ({})
this.app = new LaBoîte(repoIndex, config.version, this.domainEvents, [fetchRepoAfterConnected], log)
this.app = new LaBoîte(repoIndex, config.version, this.domainEvents, [fetchRepoAfterConnected], this.log)
})
4 changes: 1 addition & 3 deletions packages/acceptance-tests/src/support/abilities/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import { World } from '../world'

let webServer: Server

const log = process.env.show_logs ? console.log : () => ({})

Before(function (this: World) {
webServer = startWebServer(this.app, 8888, log)
webServer = startWebServer(this.app, 8888, this.log)
this.request = request(webServer)
})

Expand Down
3 changes: 2 additions & 1 deletion packages/acceptance-tests/src/support/world.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Application, CommitName, DomainEventBus, GitFile, RemoteUrl, RepoId } from 'git-en-boite-core'
import { Application, CommitName, DomainEventBus, GitFile, RemoteUrl, RepoId, WriteLogEvent } from 'git-en-boite-core'
import { Response, SuperTest, Test } from 'supertest'

export type World = {
domainEvents: DomainEventBus
log: WriteLogEvent
repoId: RepoId
lastCommitRevision: CommitName
lastResponse: Response
Expand Down
7 changes: 6 additions & 1 deletion packages/config/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ const createRedisConfig = (env: ReadableEnvironment): string => {

const createLoggerConfig = (env: ReadableEnvironment): LoggerOptions => {
return {
readableBy: env.get('NODE_ENV').required().asString() === 'production' ? 'machines' : 'humans',
readableBy:
env.get('NODE_ENV').required().asString() === 'production'
? 'machines'
: env.get('show_logs').asBool()
? 'humans'
: 'nobody',
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/logging/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export * from './makeHttpLoggingMiddleware'
export * from './LoggerOptions'

export function setUpLogger(config: pino.Bindings, { readableBy }: LoggerOptions): WriteLogEvent {
const logger = readableBy === 'humans' ? pino({ prettyPrint: { colorize: true } }) : pino()
const logger = {
machine: pino(),
humans: pino({ prettyPrint: { colorize: true } }),
nobody: pino({ level: 'silent' }),
}[readableBy]
return logToPino(logger.child(config))
}

0 comments on commit 8a75b20

Please sign in to comment.