Skip to content

Commit

Permalink
refactor: drop Contract from LoggerConfig type
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Apr 11, 2020
1 parent d528f84 commit 039dda0
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion adonis-typings/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ declare module '@ioc:Adonis/Core/Logger' {
/**
* Config shape
*/
export type LoggerConfigContract = {
export type LoggerConfig = {
name: string,
level: Level | 'silent' | string,
enabled: boolean,
Expand Down
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@
"dependencies": {
"@types/pino": "^5.17.0",
"abstract-logging": "^2.0.0",
"pino": "^6.1.1",
"ts-essentials": "^6.0.4"
"pino": "^6.1.1"
},
"directories": {
"doc": "docs",
Expand Down
5 changes: 2 additions & 3 deletions src/FakeLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
/// <reference path="../adonis-typings/logger.ts" />

import Pino from 'pino'
import { DeepReadonly } from 'ts-essentials'
import { LoggerConfigContract } from '@ioc:Adonis/Core/Logger'
import { LoggerConfig } from '@ioc:Adonis/Core/Logger'

import { Logger } from './Logger'

Expand All @@ -23,7 +22,7 @@ import { Logger } from './Logger'
* the log messages as an array vs writing them to `stdout`.
*/
export class FakeLogger extends Logger {
constructor (config: DeepReadonly<LoggerConfigContract>, pino?: Pino.Logger) {
constructor (config: LoggerConfig, pino?: Pino.Logger) {
/**
* Config is only used when we are not receiving an
* existing instance of pino.
Expand Down
5 changes: 2 additions & 3 deletions src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
/// <reference path="../adonis-typings/logger.ts" />

import Pino from 'pino'
import { DeepReadonly } from 'ts-essentials'
import abstractLogging from 'abstract-logging'
import { LoggerConfigContract, LoggerContract } from '@ioc:Adonis/Core/Logger'
import { LoggerConfig, LoggerContract } from '@ioc:Adonis/Core/Logger'

import { getPino } from './getPino'

Expand Down Expand Up @@ -48,7 +47,7 @@ export class Logger implements LoggerContract {
public pino: Pino.Logger

constructor (
protected $config: DeepReadonly<LoggerConfigContract>,
protected $config: LoggerConfig,
pino?: Pino.Logger,
) {
if (!this.$config.enabled) {
Expand Down
5 changes: 2 additions & 3 deletions src/getPino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
/// <reference path="../adonis-typings/logger.ts" />

import Pino from 'pino'
import { DeepReadonly } from 'ts-essentials'
import { LoggerConfigContract } from '@ioc:Adonis/Core/Logger'
import { LoggerConfig } from '@ioc:Adonis/Core/Logger'

/**
* Returns an instance of pino logger by adjusting the config options
*/
export function getPino (options: DeepReadonly<LoggerConfigContract>): Pino.Logger {
export function getPino (options: LoggerConfig): Pino.Logger {
const pinoOptions = Object.assign({}, options)
return options.stream ? Pino(pinoOptions as any, options.stream) : Pino(pinoOptions as any)
}

0 comments on commit 039dda0

Please sign in to comment.