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

Add cron option to suppress logging to stdout #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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