Search code examples
node.jstypescripttypeormkoa

TypeORM logging - enabled but no output


Simple issue. Typeorm doesn't log anything. I've followed the instructions on https://orkhan.gitbook.io/typeorm/docs/logging

ormconfig.json

{
  "type": "mongodb",
  "host": "aaa",
  "port": 27017,
  "username": "bbb",
  "password": "ccc",
  "ssl": true,
  "database": "db",
  "entities": ["dist/entity/*.js"],
  "logging": true
}

I've also tried logging: "all, logging: ["query"] but none of them have any effect.

Here's how I set up the app (app.ts)

createConnection()
  .then(async (connection) => {
    // create koa app
    const app = new Koa();
    const router = new Router();

    // register all application routes
    AppRoutes.forEach((route) =>
      router[route.method](route.path, route.action)
    );

    // run app
    app.use(bodyParser());
    app.use(router.routes());
    app.use(router.allowedMethods());
    app.listen(3000);

    console.log("Koa application is up and running on port 3000");
  })
  .catch((error) => console.log("TypeORM connection error: ", error));

My other console.logs show up just fine but nothing from typeorm.

I'm starting the project with tsc && node dist/app.js

After that I make an API request, query an endpoint and typeorm will go all the way thru to query Mongodb, and return back my data. But I don't see any logs.

Has anyone had this issue before, or is this a new bug?


Solution

  • Looks like a bug in typeorm if using mongodb - https://github.com/typeorm/typeorm/issues/1934

    Been open for more than a year, so doesn't look like it's getting fixed anytime soon. The reason I needed logging was to troubleshoot another problem with my setup, which now also appears to be a bug in the library. So, I think it's safe to say that typeorm/mongodb support is not reliable yet.