Giter VIP home page Giter VIP logo

Comments (3)

yellow13441 avatar yellow13441 commented on July 17, 2024

I've encountered the same problem today, loading aditional logger configuration file seems not supported in ES module projects(with type: "module" in nearest package.json) yet.

Here is how I fixed the logger customizing issue, instead of specifying an external logger configuration file, we could set FastifyServerOptions in our app.js/app.ts file.

  1. If your project was automatically generated by fastify-cli with it's template, you should find the code like below in your app.js or app.ts file.

app.ts (in my ts project)

// Pass --options via CLI arguments in command to enable these options.
const options: AppOptions = {
    logger: {
        level: 'info',
        customLevels: {
            test: 99
        }
    }
}

or app.js

// Pass --options via CLI arguments in command to enable these options.
module.exports.options = {
  logger: {
     level: 'info',
}
  1. Append -o flag in your fastify-cli command, eg. fastify start -o -P app.js

Wish this could help you with your logger issue.

from fastify-cli.

cunum avatar cunum commented on July 17, 2024

Thanks for your solution, unfortunately my multi-stream-logger.js is rather complex, I import several libraries there in order to log to console and file system simultaneously and perform log rotation of the written log files. So it's not doable via options.

My current temporary solution is I simply use this one file as CommonJS module, the rest of the files in my project are ES modules now. As the ".cjs" file extension didn't work, I created a new folder and put the multi-stream-logger.js in there together with a new package.json file with the following content (only this one line):

{ "type": "commonjs" }
That way all files in that folder are interpreted as CommonJS modules and the multi-stream-logger.js import worked.

from fastify-cli.

mhamann avatar mhamann commented on July 17, 2024

Just ran into this same issue. Our start command uses the Fastify CLI to load a specific logging module, which is a CJS file. However, it seems like the fastify cli is rewriting the filename to assume a ".js" extension? So then Node thinks it needs to be a module, but is being loaded by a synchronous, CommonJS require(), and thus it doesn't work.

from fastify-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.