Skip to content

Commit cd36f46

Browse files
committed
do not configure logging on import, use named logger
`convert_airtable.py` was configuring the logger for the root level, which clashes with other loggers that are properly configured via a logging dict, like how it's done normally in applications like django. In applications that configure their own logging this caused duplicated log lines and third-party output in seatable's format. It should be possible to toggle seatable_api logging on explicitly if it's needed. In general, libraries should only configure their own named logging space. See https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
1 parent 2e75909 commit cd36f46

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

demo/airtable_importer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import logging
34
import sys
45
from seatable_api import Base, AirtableConvertor
56
from airtable_importer_settings import server_url, api_token, airtable_api_key, airtable_base_id, \
@@ -31,6 +32,13 @@ def import_rows():
3132

3233

3334
if __name__ == '__main__':
35+
logging.basicConfig(
36+
format='[%(asctime)s] [%(levelname)s] %(message)s',
37+
datefmt='%Y-%m-%d %H:%M:%S',
38+
stream=sys.stdout,
39+
level=logging.INFO,
40+
)
41+
3442
argv_info = '\nusage :\npython3 airtable_importer.py { --import-header | --import-rows }\n'
3543

3644
if len(sys.argv) != 2:

seatable_api/convert_airtable.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import logging
33
import re
4-
import sys
54
import time
65
import random
76
import requests
@@ -27,8 +26,7 @@
2726
FILE = 'file'
2827
IMAGE = 'image'
2928

30-
logging.basicConfig(format='[%(asctime)s] [%(levelname)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S', stream=sys.stdout, level=logging.INFO)
31-
logger = logging.getLogger()
29+
logger = logging.getLogger(__name__)
3230

3331
class LinksConvertor(object):
3432

0 commit comments

Comments
 (0)