Skip to content

Disable logging in cloud-code #2518

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

Closed
DrBeak1 opened this issue Aug 14, 2016 · 6 comments
Closed

Disable logging in cloud-code #2518

DrBeak1 opened this issue Aug 14, 2016 · 6 comments

Comments

@DrBeak1
Copy link

DrBeak1 commented Aug 14, 2016

I just updated to 2.2.17; OMG - how do i disable logging in cloud code? Sorry if this has been answered somewhere else, I looked around and couldn't find anything.

I've tried changing the logLevel at app start:

// app.js
var logger = require('parse-server').logger;
logger.logLevel = process.env.PARSE_SERVER_LOG_LEVEL || 'error';

... but that doesn't seem to impact cloud code

Thanks in advance.

@acinader
Copy link
Contributor

I reproduced the issue on 2.2.17 as follows:

  • created a new dir, npm init
  • copied over my cloud code
  • added minimal dependencies:
"dependencies": {
    "eslint": "^3.3.0",
    "moment": "^2.14.1",
    "parse-image": "^0.2.0",
    "parse-server": "^2.2.17",
    "parse-server-s3-adapter": "^1.0.4",
    "twilio": "^2.9.2",
    "underscore": "^1.8.3"
  }
  • created minimal index.js:
const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const S3Adapter = require('parse-server-s3-adapter');

const parseServerOptions = {
  logLevel: 'warn',
  appId: 'XXXX',
  masterKey: 'XXX',
  databaseURI: 'XXX',
  serverURL: 'http://localhost:9091/parse',
  port: 9091,
  cloud: './cloud/main.js',
  fileKey: 'XXXX,
  filesAdapter: new S3Adapter({
    bucket: 'XXX',
    bucketPrefix: 'files-dev/',
    directAccess: true,
    baseUrl: 'XXX,
    globalCacheControl: 'public, max-age=31536000',
  }),
};

const app = express();
const api = new ParseServer(parseServerOptions);
const port = 9091;

app.use('/parse', api);

app.listen(port, () => {
  console.log('listening on ' + port);
});

module.exports = app;
  • then I start the server with:
PARSE_SERVER_LOG_LEVEL=warn S3_ACCESS_KEY=$AWS_ACCESS_KEY_ID S3_SECRET_KEY=$AWS_SECRET_ACCESS_KEY nodemon index.js

Note that I am double setting warning: both in the config obj and on the command line.

I then hit it with our app and it works just fine, but I am getting info logs.

I tried to get a unit test to fail on master, but it works. Here's the unit test:

acinader@ec3c5d8

I'm going to checkout the behavior on master since the big logging refactor.

@acinader
Copy link
Contributor

acinader commented Aug 15, 2016

Ok, so after much wrangling and a bug discovered in my own logging adapter, I can configure log level on MASTER.

Two ways I can do it:

  1. if I don't configure a logging adapter and just accept the default logger, if I set logLevel in the options i pass to the parse constructor, the logLevel will be set.
  2. I can also configure a logger (in this case the WinstonLoggerAdapter) and I can pass logLevel as an option. If I pass any options when adding a LoggerAdapter then the parse-server option logLevel is ignored.

If i have my testing right, then setting the env var PARSE_SERVER_LOG_LEVEL does not work on master. Though in my admittedly rudimentary understanding of cli-definitions.js, I don't see why this isn't working, so its probably my testing.....

@DrBeak1
Copy link
Author

DrBeak1 commented Aug 16, 2016

@acinader thanks so much for digging into this.

I just tried ...

var api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev',
  cloud: '/home/myApp/cloud/main.js',
  appId: 'myAppId',
  masterKey: 'myMasterKey',
  fileKey: 'optionalFileKey',
  serverURL: 'http://localhost:1337/parse',
  logLevel: 'error' <====== set level here?
});

... but I'm still seeing logging from cloud code. Is this what you were referring to above as working?

edit: Ah! you did this on master though, I tried on 2.2.17 ...

@acinader
Copy link
Contributor

acinader commented Aug 16, 2016

@DrBeak1, futzed a little more. this will turn it off in 2.2.17 (some things to note at the bottom...):

const express = require('express');
const ParseServer = require('parse-server').ParseServer;
const S3Adapter = require('parse-server-s3-adapter');
const configureLogger = require('parse-server/lib/logger').configureLogger;
const logger = require('parse-server').logger;

// Note that I am not using the same port as you!!!
const port = 9091;

const parseServerOptions = {
  appId: 'xxx',
  masterKey: 'xxx',
  databaseURI: 'xxx',
  serverURL: 'http://localhost:9091/parse',
  port: port,
  cloud: './cloud/main.js',
  fileKey: 'xxxx',
  filesAdapter: new S3Adapter({
    bucket: 'xxx',
    bucketPrefix: 'xxx/',
    directAccess: true,
    baseUrl: 'https://xxx',
    globalCacheControl: 'public, max-age=31536000',
  })
};

const app = express();
const api = new ParseServer(parseServerOptions);

configureLogger({ level: 'warn' });

app.use('/parse', api);

app.listen(port, () => {
  logger.info('info');
  logger.warn('warn');
  logger.warn('listening on ' + port);

});

module.exports = app;
  1. I didn't check what this does to the other options for the logger, so these are the other options you MAY need to add your values for logsFolder and jsonLogs
  2. keep an eye out for when the next version bump of parse-server comes out and then you'll be able to set like you did above.
  3. keep an eye on Make Logging More Useful #2501. I intend to work on this today with the goal to get the logging as close to what was on parse.com at which point you may want to switch back to info from warn.

And finally, if this answers your question, close the issue?

@DrBeak1
Copy link
Author

DrBeak1 commented Aug 17, 2016

Thanks again, @acinader -- I'll give this a shot tonight and report back.

@DrBeak1
Copy link
Author

DrBeak1 commented Aug 18, 2016

@acinader I can confirm that your last suggestion does in fact work. Thank you, sir!

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