Skip to content
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

Best way to log from cloud code? #1904

Closed
jeveloper opened this issue May 25, 2016 · 3 comments · May be fixed by LadyK-21/parse-server#8
Closed

Best way to log from cloud code? #1904

jeveloper opened this issue May 25, 2016 · 3 comments · May be fixed by LadyK-21/parse-server#8

Comments

@jeveloper
Copy link
Contributor

This is a question.

I was reviewing a commit and notice there is winston used for logging.
https://github.com/ParsePlatform/parse-server/blob/fece2a4b47f1469c6371c39bca63df85276e7d5f/src/logger.js

What's the best way of logging from cloud_code/main.js , it used to be console.log or console.error, is there a way to get access to winston instance?

Thank you

@ndnguru
Copy link

ndnguru commented May 25, 2016

you can do something like this:

when you start your parse-server, configure the logger adapter like this (refer to issue #781)

var logger = require('parse-server/lib/Adapters/Logger/FileLoggerAdapter').FileLoggerAdapter;

// ...

var api = new ParseServer({
  databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || 'myAppId',
  masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
  serverURL: process.env.SERVER_URL || 'http://localhost:1337',  // Don't forget to change to https if needed
  loggerAdapter: new logger({ logsFolder: './' })
});

in your main.js:

Parse.Cloud.define('someCouldCodeFunctionName',
    function(request, response) {
        console.log('This will log to the console');
        request.log.info("This will log to the file ", {user:request.user, params:request.params});
        ....        
});

@jeveloper
Copy link
Contributor Author

Thanks for the tip, i guess default setup doesnt expose logger then.

@sprabs
Copy link

sprabs commented Sep 5, 2016

Is this still valid, though? I'm pretty confused by the conversation on: #2478

Looks like the logger setup in index.js is different now. I'm just trying to figure out how to make it work. Even with verbose set to true, I'm not seeing logs anymore with the latest parse-server code...

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

Successfully merging a pull request may close this issue.

3 participants