Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage in TypeScript? #80

Open
cklat opened this issue Sep 30, 2024 · 3 comments
Open

Usage in TypeScript? #80

cklat opened this issue Sep 30, 2024 · 3 comments

Comments

@cklat
Copy link

cklat commented Sep 30, 2024

Hi,

I came across this library due to all the limitation NextJS has with logging and trying to use it in my TypeScript. Unfortunately, not successful.

What I have tried is to follow the example for the custom logging in the documentation and use it like I would normally use the Pino Logger like so:

//next-logger.config.ts

import pino from 'pino';
  
const logger = (defaultConfig: any) =>
	pino({
		...defaultConfig,
		formatters: {
			level: (label) => {
				return { level: label };
			},
		},
	}, pino.destination(`${__dirname}/logs/logfile.log`));

export default {
	logger,
};

//random-usage-file.ts

import logger from './next-logger.config';

logger.info('Some debug log');

However, I'm getting the following: Property 'info' does not exist on type '{ logger: (defaultConfig: any) => Logger<never, boolean>; }'

Any ideas how to get this to work?

@dir
Copy link

dir commented Sep 30, 2024

From my personal experience messing around with it a bit, this package seems to be very TypeScript-unfriendly.

@atkinchris
Copy link
Collaborator

We exclusively use this with TypeScript projects internally, so I'm disappointed to see you're facing issues. Because of when we need to patch Next.js in the applications lifecycle, this doesn't lend itself well to being compiled with TypeScript or referenced back into TypeScript projects.

Generally, we'd import the Pino config into this next-logger.config file, rather than it being the source of truth for Pino's config. You may need to reference the compiled output directly - as this happens at runtime, and isn't compiled.

@cklat
Copy link
Author

cklat commented Oct 7, 2024

@atkinchris

I'm not sure if I follow you, sorry.

Is it possible that you can provide some example code that shows what you mean and may fix the above error I'm encountering?

Appreciate it, thanks!

edit//

My use case and thus my implementation has a little changed but the problem still persists.
I',m trying to achieve a logging with a context propagation. For this I'm trying to incorporate the NodeJS Async Local Storage.

My files look the following:

[...]

I have found the mistake. In the end, it was nothing related to the error I had in my original post.
Sorry for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants