hapijs / good

hapi process monitoring
Other
525 stars 160 forks source link

I have the proper setup as per the documentation, but still the logs are not showing. #626

Closed rajeshwarpatlolla closed 5 years ago

rajeshwarpatlolla commented 5 years ago

My setup is

const goodOptions = {
    ops: {
      interval: 1000,
    },
    reporters: {
      console: [
        {
          module: '@hapi/good-squeeze',
          name: 'Squeeze',
          args: [{ log: '*', response: '*' }],
        },
        {
          module: '@hapi/good-console',
        },
        'stdout',
      ],
    },
  };`

 await server.register([
    Inert,
    Vision,
    {
      plugin: HapiSwagger,
      options: swaggerOptions,
    },
    {
      plugin: require('@hapi/good'),
      goodOptions,
    },
  ]);

When i run my server, server is starting and the apis are working fine. But i don't see any logs.

    "@hapi/good": "^8.2.2",
    "@hapi/good-console": "^8.1.2",
    "@hapi/good-squeeze": "^5.2.1",
    "@hapi/hapi": "^18.3.2",
    "@hapi/inert": "^5.2.1",
    "@hapi/joi": "^15.1.1",
    "@hapi/vision": "^5.5.3",

node -v
v10.16.0

npm -v
6.9.0

Any help would be really appreciated.

rajeshwarpatlolla commented 5 years ago

I am using the same setup, but still not working. Don't be in a hurry to close the issue. Let's agree that, it's working first and then we can close it. If you close it, those who have some idea on it, will never look at this issue. Please re open this issue. Let me get some help from those who know the solution please.

hueniverse commented 5 years ago

I updated the examples. I tested each one of them today. They all work. I suggest you look at them and make sure they are working as-is first and once you get them to work, figure out your own problem.

And you are not using the same setup! For one, you are enabling ops but filtering them out with { log: '*', response: '*' }. Try { log: '*', response: '*', ops: '*' } instead.

rajeshwarpatlolla commented 5 years ago

I tried this as well.

Screenshot 2019-09-22 at 2 22 32 PM

I made few api calls, but i don't see any response on the console.

Marsup commented 5 years ago

Then show the full code, because you're doing something wrong somewhere, and we can't help you with glimpses of partial code.

rajeshwarpatlolla commented 5 years ago

Here is the complete code of main file of the application

'use strict';

const Hapi = require('@hapi/hapi');
const Inert = require('@hapi/inert');
const Vision = require('@hapi/vision');
const HapiSwagger = require('hapi-swagger');
const mongoose = require('mongoose');

const Config = require('./config');
const Routes = require('./routes');
const Pack = require('./package');

mongoose.connect(Config.database.uri, { useNewUrlParser: true, useCreateIndex: true });

let db = mongoose.connection;

db.on('connected', function callback() {
  console.log('Connected to DB.');
  init();
});

db.on('error', function() {
  console.log('Connection to DB failed!');
  process.exit(0);
});

db.on('disconnected', function(err) {
  console.log('Connection teminated to DB ', err);
  process.exit(0);
});

const init = async () => {
  const server = Hapi.server({
    host: Config.server.host,
    port: Config.server.port,
    routes: {
      cors: true,
      validate: {
        // If any Joi validations fail, it will send the proper error message to the user
        failAction: (request, h, err) => {
          throw err;
        },
      },
    },
  });

  const swaggerOptions = {
    info: {
      title: Config.swagger.title,
      version: Pack.version,
      contact: {
        name: Config.swagger.contact,
      },
    },
    schemes: ['http', 'https'],
    securityDefinitions: {
      jwt: {
        type: 'apiKey',
        name: 'Authorization',
        in: 'header',
      },
    },
    security: [{ jwt: [] }],
  };

  const goodOptions = {
    ops: {
      interval: 1000,
    },
    reporters: {
      console: [
        {
          module: '@hapi/good-squeeze',
          name: 'Squeeze',
          args: [{ log: '*', response: '*', ops: '*' }],
        },
        {
          module: '@hapi/good-console',
        },
        'stdout',
      ],
    },
  };

  await server.register([
    Inert,
    Vision,
    {
      plugin: HapiSwagger,
      options: swaggerOptions,
    },
    {
      plugin: require('@hapi/good'),
      goodOptions,
    },
  ]);

  try {
    await server.start();
    console.log(`Server running on ${server.info.uri}`);
    console.log(`Swagger documentation is running on ${server.info.uri}/documentation`);
  } catch (err) {
    console.log(err);
  }
  server.route(Routes);

  server.ext('onPostAuth', async (req, h) => {
    return h.continue;
  });
};

process.on('unhandledRejection', err => {
  console.error(err);
  process.exit(1);
});

I tried adding a static router as mentioned here, but still same issue. I don't see any logs.

Marsup commented 5 years ago

Well, appears you didn't have the proper setup. If you rename goodOptions to options it will be a whole lot better.

rajeshwarpatlolla commented 5 years ago

Oh yea, sorry. I modified recently forgot to rename it. I made changes, but still i am getting no logs.

Screenshot 2019-09-22 at 8 04 23 PM
Marsup commented 5 years ago

Well I do, so make sure you double checked everything.

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.