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

Cannot Disable Logging - directory is always created #6307

Closed
REPTILEHAUS opened this issue Dec 29, 2019 · 15 comments
Closed

Cannot Disable Logging - directory is always created #6307

REPTILEHAUS opened this issue Dec 29, 2019 · 15 comments
Labels
bounty:$20 Bounty applies for fixing this issue (Parse Bounty Program) type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@REPTILEHAUS
Copy link

Im trying to integrate the default winston logger with the Google Cloud stack driver adapter but cant figure out how to integrate it

Do you guys have any pointers on this library ?
https://github.com/googleapis/nodejs-logging-winston

trying this at the moment but its not working

var WinstonLoggerAdapter = require('parse-server/lib/Adapters/Logger/WinstonLoggerAdapter');

const {LoggingWinston} = require('@google-cloud/logging-winston');

const loggingWinston = new LoggingWinston();
....
    loggerAdapter: {
        module: WinstonLoggerAdapter,
        options: {
          level: 'info',
          jsonLogs: true,
          transports: [
            // Add Stackdriver Logging
            loggingWinston,
          ],          
        },          
    },

Similar issues:
#2501
#2550
#1904

@REPTILEHAUS
Copy link
Author

I have gotten it implemented however the issue remains that the default logging of parse still creates a log dir

var ParseServer = require('parse-server').ParseServer
var logger = require('parse-server').logger

// Imports the Google Cloud client library for Winston
const {LoggingWinston} = require('@google-cloud/logging-winston');

logger.options = {
    logsFolder: null,
    jsonLogs: false,
    verbose: false,
    silent: undefined
}

logger.adapter.addTransport( new LoggingWinston({
    projectId: parseConfig.gcpProjectId,
    credentials: {
        client_email: serviceAccount.client_email,
        private_key: serviceAccount.private_key
    },    
  }));

  
  try {
    logger.error('warp nacelles offline '+ env);
    logger.info('shields at 99%'+ env);      
  } catch (error) {
      console.log(error)
  }

This is causing issues in my GAE environment as writing directories is not allowed, I have also specified in logsFolder: null, in my parse init

@REPTILEHAUS
Copy link
Author

REPTILEHAUS commented Dec 30, 2019

Other related issues and approaches I have tried

#2855
#2518
#6205
#391

@REPTILEHAUS REPTILEHAUS changed the title Integrate Stackdriver logging for Winston Cannot Disable Logging - directory is always created Dec 30, 2019
@REPTILEHAUS
Copy link
Author

Strange behaviour, even when specifying an alternative logs directory name (other than null) parse still creates a logs folder as well as the other custom folder

@REPTILEHAUS
Copy link
Author

After some source code review Ive found a work around by setting process.env.PARSE_SERVER_LOGS_FOLDER=null

Seems ./src/Options/index.ts maybe should have the type logsFolder: string | null ? Im not sure about the internals of parse or what to tweak or id submit a PR but I think it can be corrected in this block in ./src/defaults.js

const { ParseServerOptions } = require('./Options/Definitions');
const logsFolder = (() => {
  let folder = './logs/';
  if (typeof process !== 'undefined' && process.env.TESTING === '1') {
    folder = './test_logs/';
  }
  if (process.env.PARSE_SERVER_LOGS_FOLDER) {
    folder = nullParser(process.env.PARSE_SERVER_LOGS_FOLDER);
  }
  return folder;
})(); 

@santiagosemhan
Copy link

+1
I'm setting logsFolder to null but the Log folder and empty files each day are still created.

I'm using the following configuration:

const api = new ParseServer({
  databaseURI: mongoDSN, 
  cloud: './cloud/main.js', 
  allowClientClassCreation: false,
  appId,
  masterKey, 
  logsFolder: null,
  verbose: false,
  silent: false,
  ...

Parse Server version: 3.10.0

@davimacedo
Copy link
Member

Have you tried with process.env.PARSE_SERVER_LOGS_FOLDER=null like @REPTILEHAUS suggested?

@santiagosemhan
Copy link

Hi @davimacedo ! If I set process.env.PARSE_SERVER_LOGS_FOLDER=null logs folder It's not being created but I think that conf object passed to ParseServer instance should be taken into account in order to config log folder too.

Thanks

@davimacedo
Copy link
Member

Got it. This is something that can be really improved. Do you want to tackle this one?

@davimacedo davimacedo added type:bug Impaired feature or lacking behavior that is likely assumed good first issue labels Feb 12, 2020
@santiagosemhan
Copy link

I spent a lot of time trying to figure out where the problem was but honestly I couldn't find it. If you can give me a clue maybe I could tackle this!

@davimacedo
Copy link
Member

If you set logsFolder to any other folder than not the default, does it work? I guess this option is only working through env vars.

@santiagosemhan
Copy link

santiagosemhan commented Feb 13, 2020 via email

@dplewis
Copy link
Member

dplewis commented Feb 13, 2020

Although the server doesn't create the folder. Winston creates it internally I believe

@santiagosemhan
Copy link

I thought the same thing but the question is Why if you set PARSE_SERVER_LOGS_FOLDER env var to null the folder is not created?

@mtrezza mtrezza added the bounty:$20 Bounty applies for fixing this issue (Parse Bounty Program) label Nov 26, 2022
@mtrezza
Copy link
Member

mtrezza commented Nov 29, 2022

The most likely solution is to remove the instruction to set logFolder: null as interpreting a null value can be problematic.

Suggested change:

  • Setting logFolder to anything else than a string should throw an error, the type should be string only.
  • Add new log level none to logLevel that disables logging completely.

Anyone would like to pick this up?

@dplewis
Copy link
Member

dplewis commented Jul 17, 2024

I thought the same thing but the question is Why if you set PARSE_SERVER_LOGS_FOLDER env var to null the folder is not created?

The server has 2 loggers. You have to disable both loggers to prevent a directory from being created and PARSE_SERVER_LOGS_FOLDER does that. You can't use logsFolder to disable it is because one of the loggers is the default logger which is created before you have a chance to pass server options to it

Object.defineProperty(module.exports, 'logger', {
get: getLogger,
});

Please create a new issue if the problem still exists.

@dplewis dplewis closed this as completed Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty:$20 Bounty applies for fixing this issue (Parse Bounty Program) type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

5 participants