Skip to content

Conversation

@mape2k
Copy link
Contributor

@mape2k mape2k commented Oct 31, 2019

Hello MrBE4R,

this commit add a new option to suppress logging to stdout if script is used in cronjobs.

Copy link
Owner

@MrBE4R MrBE4R left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition, I usually redirect stdout output to /dev/null in crontab.

Comment on lines +21 to +22
if config is None:
logstdout('Initializing gitlab-ldap-sync failed.')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be within the else at the end of this script

Comment on lines +11 to 18
CRON = False

def logstdout(s):
if not CRON:
print(s)

if __name__ == "__main__":
print('Initializing gitlab-ldap-sync.')
config = None
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a global CRON in both logstdout and __main__ to ensure we use the same variable

Comment on lines +24 to +27
logstdout('Initializing gitlab-ldap-sync successfull.')
if config['cron']:
CRON = True
logstdout('Updating logger configuration')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consitent this should be something like this :

        CRON = config['cron']
        logstdout('Initializing gitlab-ldap-sync successfull.')
        logstdout('Updating logger configuration')

Comment on lines +36 to +39
if config['cron'] and config['log']:
console = logging.StreamHandler()
console.setLevel(logging.ERROR)
logging.getLogger('').addHandler(console)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this part. We already suppress "print" logs and you can set the log level in config.json

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 this pull request may close these issues.

2 participants