Comments (3)
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.
- 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',
}
- 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.
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.
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)
- Allow add plugin to main process scope ( not app.js scope ), without eject the project. HOT 1
- Allow `build` from `'fastify-cli/helper.js'` to accept an existing module object
- Add support for generate-swagger to generate in YAML format HOT 3
- TypeScript Option Produces Inoperable Code - Bundled TypeScript Version? HOT 1
- Cannot use --require option is ESM project HOT 3
- Generated project doesn't work out of the box with --esm --lang=ts HOT 2
- Need better `eject`
- Can't add schema to route HOT 1
- Route URL case sensitivity HOT 20
- Generate plugin nitpicks to work out of the box
- Core plugin installation utility HOT 4
- package.json file already exists in target directory HOT 2
- c8 dependency is not added with fastify generate project_name --lang=ts HOT 1
- How to configure project to run as https in development mode HOT 2
- How to run a fastify server in production HOT 2
- Watcher is not working on builders
- Does Platformatic Replace fastify-cli ? HOT 1
- Dependency update for v5
- with 'nom run start' error: Missing the required file parameter shows up
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-cli.