-
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,23 @@ | |
import ldap.asyncsearch | ||
import logging | ||
|
||
CRON = False | ||
|
||
def logstdout(s): | ||
if not CRON: | ||
print(s) | ||
|
||
if __name__ == "__main__": | ||
print('Initializing gitlab-ldap-sync.') | ||
config = None | ||
with open('config.json') as f: | ||
config = json.load(f) | ||
if config is None: | ||
logstdout('Initializing gitlab-ldap-sync failed.') | ||
Comment on lines
+21
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be within the |
||
if config is not None: | ||
print('Done.') | ||
print('Updating logger configuration') | ||
logstdout('Initializing gitlab-ldap-sync successfull.') | ||
if config['cron']: | ||
CRON = True | ||
logstdout('Updating logger configuration') | ||
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be consitent this should be something like this :
|
||
log_option = { | ||
'format': '[%(asctime)s] [%(levelname)s] %(message)s' | ||
} | ||
|
@@ -24,7 +33,11 @@ | |
if config['log_level']: | ||
log_option['level'] = getattr(logging, str(config['log_level']).upper()) | ||
logging.basicConfig(**log_option) | ||
print('Done.') | ||
if config['cron'] and config['log']: | ||
console = logging.StreamHandler() | ||
console.setLevel(logging.ERROR) | ||
logging.getLogger('').addHandler(console) | ||
Comment on lines
+39
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
logstdout('Done.') | ||
logging.info('Connecting to GitLab') | ||
if config['gitlab']['api']: | ||
gl = 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 bothlogstdout
and__main__
to ensure we use the same variable