-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
if config is None: | ||
logstdout('Initializing gitlab-ldap-sync failed.') |
There was a problem hiding this comment.
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
CRON = False | ||
|
||
def logstdout(s): | ||
if not CRON: | ||
print(s) | ||
|
||
if __name__ == "__main__": | ||
print('Initializing gitlab-ldap-sync.') | ||
config = None |
There was a problem hiding this comment.
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
logstdout('Initializing gitlab-ldap-sync successfull.') | ||
if config['cron']: | ||
CRON = True | ||
logstdout('Updating logger configuration') |
There was a problem hiding this comment.
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')
if config['cron'] and config['log']: | ||
console = logging.StreamHandler() | ||
console.setLevel(logging.ERROR) | ||
logging.getLogger('').addHandler(console) |
There was a problem hiding this comment.
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
Hello MrBE4R,
this commit add a new option to suppress logging to stdout if script is used in cronjobs.