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

Disable Fastify logger in production #124

Closed
2 tasks
amit548 opened this issue Nov 26, 2021 · 2 comments
Closed
2 tasks

Disable Fastify logger in production #124

amit548 opened this issue Nov 26, 2021 · 2 comments

Comments

@amit548
Copy link

amit548 commented Nov 26, 2021

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

I want to disable Fastify logger in production mode using fastify-env, but I'm not able to collect NODE_ENV from process.env when using fastify-env.

import fastify from 'fastify';
import fastifyEnv from 'fastify-env';

declare module 'fastify' {
  interface FastifyInstance {
    config: {
      NODE_ENV: string;
    };
  }
}

const app = fastify({
  logger:
    process.env.NODE_ENV === 'development'
      ? {
          prettyPrint: {
            levelFirst: true,
            translateTime: 'HH:MM:ss Z',
            ignore: 'pid,hostname',
          },
        }
      : false,
});

const start = async () => {
  try {
    await app.register(fastifyEnv, {
      dotenv: true,
      confKey: 'config',
      schema: {
        type: 'object',
        properties: {
          NODE_ENV: {
            type: 'string',
            enum: ['development', 'production'],
          },
        },
        required: ['NODE_ENV'],
      },
    });

    await app.ready();
    await app.listen(3000);
  } catch (error) {
    app.log.error(error);
    process.exit(1);
  }
};
start();

@climba03003
Copy link
Member

It is impossible to get something before it is actually initialized.
Please use env-schema for sync loading of env.

@amit548
Copy link
Author

amit548 commented Nov 26, 2021

It is impossible to get something before it is actually initialized. Please use env-schema for sync loading of env.

Thanks

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

2 participants