Skip to content

Conversation

@Ethan-Arrowood
Copy link
Member

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

Not complete yet. I want to add a standalone typescript test file that tests the logger types I've defined. I think using the atomic approach to types declarations and testing will be the best way of improving type support across the project.

In this PR I have declared the types for the fastify instance logger option parameter. It was previously defined as any. I am not sure if this is considered breaking or not because:

  • Non TS devs will not witness any change
  • TS devs who were incorrectly defining logging options were not following the JS API.

Furthermore on that second bullet, I'd like to update the logging documentation to be more explicit about what options users have for logging

  1. Boolean, defaults to pino with no special configuration
  2. Pass an object with Pino options
  3. Pass an object that implements a 'valid logger'

a 'valid logger' could be better documented as the current line (in reference to custom serializers)

This option will be ignored by any logger other than Pino.
Is not entirely true because a correctly implemented custom logger (with all of the level methods) and a set of valid serializers will generated into a valid logger by the createLogger method.

@Ethan-Arrowood Ethan-Arrowood added the typescript TypeScript related label Mar 13, 2019
import * as http from 'http'
import * as http2 from 'http2'
import * as https from 'https'
import * as pino from 'pino'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided not to ship pino types. Pino does not have official types support and it relies on @types/pino.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the import for it is the same. I downloaded @types/pino as devDep

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done on purpose and should be reverted. For Fastify v2 we decided not to ship these types.

@Ethan-Arrowood
Copy link
Member Author

@evanshortiss do you have any tips for how I can make use of the HttpRequest and HttpResponse generics?

@delvedor delvedor added the v2.x Issue or pr related to Fastify v2 label Mar 14, 2019
@evanshortiss
Copy link
Member

@Ethan-Arrowood I think it looks like your doing it the right way, though it might need to include http2 like so?

export default interface FastifyLoggerOptions<
  HttpRequest extends (http.IncomingMessage | http2.Http2ServerRequest) = http.IncomingMessage,
  HttpResponse extends (http.ServerResponse | http2.Http2ServerResponse) = http.ServerResponse
>

genReqId?: string;
}

type WriteFn = (o: object) => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense if this was:

type WriteFn = (...args: any[]) => void;

Since it's a pino logger you can pass multiple args? Or am I mistaken to believe this? For example, it should be valid to do:

fastify.log.info('here is your json %j', someJson)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is a valid log invocation @evanshortiss .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current types have two methods defined. I'm working on merging the two right now.

declare type WriteFn = (msg:string, ...args: any[]) => void;
declare type WriteFn = (obj: {}, msg?: string, ...args: any[]) => void;

TypeScript says I can't do it this way so I'm working on it 😅

@Ethan-Arrowood
Copy link
Member Author

Thank you to everyone who has looked over this PR. I'm going to mark this as invalid for right now because I'm currently working on implementing these types in a different way (that I think is going to be better for a couple of reasons). More to come soon!

@stale
Copy link

stale bot commented Mar 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue or pr with more than 15 days of inactivity. label Mar 30, 2019
@cemremengu
Copy link
Contributor

@Ethan-Arrowood should this be closed?

@stale stale bot removed the stale Issue or pr with more than 15 days of inactivity. label Mar 30, 2019
@Ethan-Arrowood
Copy link
Member Author

Ethan-Arrowood commented Mar 30, 2019 via email

@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 10, 2022
@Eomm Eomm added the wontfix This will not be worked on, the behavior is intended label Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

typescript TypeScript related v2.x Issue or pr related to Fastify v2 wontfix This will not be worked on, the behavior is intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants