|
20 | 20 | import os
|
21 | 21 |
|
22 | 22 | from airflow import configuration as conf
|
| 23 | +from airflow.utils.file import mkdirs |
23 | 24 |
|
24 | 25 | # TODO: Logging format and level should be configured
|
25 | 26 | # in this file instead of from airflow.cfg. Currently
|
|
38 | 39 |
|
39 | 40 | PROCESSOR_LOG_FOLDER = conf.get('scheduler', 'CHILD_PROCESS_LOG_DIRECTORY')
|
40 | 41 |
|
| 42 | +DAG_PROCESSOR_MANAGER_LOG_LOCATION = \ |
| 43 | + conf.get('core', 'DAG_PROCESSOR_MANAGER_LOG_LOCATION') |
| 44 | + |
41 | 45 | FILENAME_TEMPLATE = conf.get('core', 'LOG_FILENAME_TEMPLATE')
|
| 46 | + |
42 | 47 | PROCESSOR_FILENAME_TEMPLATE = conf.get('core', 'LOG_PROCESSOR_FILENAME_TEMPLATE')
|
43 | 48 |
|
44 | 49 | # Storage bucket url for remote logging
|
|
79 | 84 | 'formatter': 'airflow',
|
80 | 85 | 'base_log_folder': os.path.expanduser(PROCESSOR_LOG_FOLDER),
|
81 | 86 | 'filename_template': PROCESSOR_FILENAME_TEMPLATE,
|
82 |
| - }, |
| 87 | + } |
83 | 88 | },
|
84 | 89 | 'loggers': {
|
85 | 90 | 'airflow.processor': {
|
|
104 | 109 | }
|
105 | 110 | }
|
106 | 111 |
|
| 112 | +DEFAULT_DAG_PARSING_LOGGING_CONFIG = { |
| 113 | + 'handlers': { |
| 114 | + 'processor_manager': { |
| 115 | + 'class': 'logging.handlers.RotatingFileHandler', |
| 116 | + 'formatter': 'airflow', |
| 117 | + 'filename': DAG_PROCESSOR_MANAGER_LOG_LOCATION, |
| 118 | + 'mode': 'a', |
| 119 | + 'maxBytes': 104857600, # 100MB |
| 120 | + 'backupCount': 5 |
| 121 | + } |
| 122 | + }, |
| 123 | + 'loggers': { |
| 124 | + 'airflow.processor_manager': { |
| 125 | + 'handlers': ['processor_manager'], |
| 126 | + 'level': LOG_LEVEL, |
| 127 | + 'propagate': False, |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | + |
107 | 132 | REMOTE_HANDLERS = {
|
108 | 133 | 's3': {
|
109 | 134 | 'task': {
|
|
172 | 197 |
|
173 | 198 | REMOTE_LOGGING = conf.get('core', 'remote_logging')
|
174 | 199 |
|
| 200 | +# Only update the handlers and loggers when CONFIG_PROCESSOR_MANAGER_LOGGER is set. |
| 201 | +# This is to avoid exceptions when initializing RotatingFileHandler multiple times |
| 202 | +# in multiple processes. |
| 203 | +if os.environ.get('CONFIG_PROCESSOR_MANAGER_LOGGER') == 'True': |
| 204 | + DEFAULT_LOGGING_CONFIG['handlers'] \ |
| 205 | + .update(DEFAULT_DAG_PARSING_LOGGING_CONFIG['handlers']) |
| 206 | + DEFAULT_LOGGING_CONFIG['loggers'] \ |
| 207 | + .update(DEFAULT_DAG_PARSING_LOGGING_CONFIG['loggers']) |
| 208 | + |
| 209 | + # Manually create log directory for processor_manager handler as RotatingFileHandler |
| 210 | + # will only create file but not the directory. |
| 211 | + processor_manager_handler_config = DEFAULT_DAG_PARSING_LOGGING_CONFIG['handlers'][ |
| 212 | + 'processor_manager'] |
| 213 | + directory = os.path.dirname(processor_manager_handler_config['filename']) |
| 214 | + mkdirs(directory, 0o755) |
| 215 | + |
175 | 216 | if REMOTE_LOGGING and REMOTE_BASE_LOG_FOLDER.startswith('s3://'):
|
176 | 217 | DEFAULT_LOGGING_CONFIG['handlers'].update(REMOTE_HANDLERS['s3'])
|
177 | 218 | elif REMOTE_LOGGING and REMOTE_BASE_LOG_FOLDER.startswith('gs://'):
|
|
0 commit comments