提交 1caf7662 编写于 作者: T tssujt

Proofread write-logs section

上级 3828733d
......@@ -62,7 +62,7 @@
| [9 使用操作器](zh/9.md) | [@ImPerat0R\_](https://github.com/tssujt) |
| [10 管理连接](zh/10.md) | [@ImPerat0R\_](https://github.com/tssujt) |
| [11 保护连接](zh/11.md) | [@ImPerat0R\_](https://github.com/tssujt) |
| [12 写日志](zh/12.md) | |
| [12 写日志](zh/12.md) | [@ImPerat0R\_](https://github.com/tssujt) |
| [13 用Celery扩大规模](zh/13.md) | |
| [14 用Dask扩展](zh/14.md) | |
| [15 使用Mesos扩展(社区贡献)](zh/15.md) | |
......
# 写日志
## 在本地写日志
## 在本地写日志
用户可以使用`base_log_folder`设置在`airflow.cfg`指定日志文件夹。 默认情况下,它位于`AIRFLOW_HOME`目录中。
用户可以使用`airflow.cfg`中的`base_log_folder`指定日志文件夹。默认情况下,它位于`AIRFLOW_HOME`目录中。
此外,用户可以提供远程位置,以便在云存储中存储日志和日志备份。
此外,用户可以提供远程位置,以便在云存储中存储日志和日志备份。
在Airflow Web UI中,本地日志优先于远程日志。 如果找不到或访问本地日志,将显示远程日志。 请注意,只有在任务完成(包括失败)后才会将日志发送到远程存储。 换句话说,运行任务的远程日志不可用。 日志作为`{dag_id}/{task_id}/{execution_date}/{try_number}.log`存储在日志文件夹中。
在Airflow Web UI中,本地日志优先于远程日志。 如果找不到或访问本地日志,将显示远程日志。 请注意,只有在任务完成(包括失败)后才会将日志发送到远程存储。 换句话说,运行任务的远程日志不可用。日志以`{dag_id}/{task_id}/{execution_date}/{try_number}.log`的路径格式存储在日志文件夹中。
## 将日志写入Amazon S3
### 在你开始之前
远程日志记录使用现有的Airflow连接来读取/写入日志。 如果没有正确设置连接,则会失败。
远程日志记录使用现有的Airflow连接来读取/写入日志。如果没有正确设置连接,则会失败。
### 启用远程日志记录
要启用此功能,必须按照此示例配置`airflow.cfg`
```
[ core ]
# Airflow can store logs remotely in AWS S3\. Users must supply a remote
[core]
# Airflow can store logs remotely in AWS S3. Users must supply a remote
# location URL (starting with either 's3://...') and an Airflow connection
# id that provides access to the storage location.
remote_base_log_folder = s3://my-bucket/path/to/logs
remote_log_conn_id = MyS3Conn
# Use server-side encryption for logs stored in S3
encrypt_s3_logs = False
```
在上面的例子中,Airflow将尝试使用`S3Hook('MyS3Conn')`
## 将日志写入Azure Blob存储
可以将Airflow配置为在Azure Blob存储中读取和写入任务日志。 按照以下步骤启用Azure Blob存储日志记录。
1. Airflow的日志记录系统需要将自定义.py文件放在`PYTHONPATH` ,以便可以从Airflow导入。 首先创建一个存储配置文件的目录。 建议使用`$AIRFLOW_HOME/config`
2. 创建名为`$AIRFLOW_HOME/config/log_config.py``$AIRFLOW_HOME/config/__init__.py`空文件。
## 将日志写入Azure Blob Storage
3.`airflow/config_templates/airflow_local_settings.py`的内容复制到刚刚在上面的步骤中创建的`log_config.py`文件中
可以将Airflow配置为在Azure Blob Storage中读取和写入任务日志。 按照以下步骤启用Azure Blob Storage日志记录
4. 自定义模板的以下部分:
1. Airflow的日志记录系统需要将自定义.py文件放在`PYTHONPATH`,以便可以从Airflow导入。首先创建一个存储配置文件的目录。建议使用`$AIRFLOW_HOME/config`
> ```
> # wasb buckets should start with "wasb" just to help Airflow select correct handler
> REMOTE_BASE_LOG_FOLDER = 'wasb-<whatever you want here>'
>
> # Rename DEFAULT_LOGGING_CONFIG to LOGGING CONFIG
> LOGGING_CONFIG = ...
>
> ```
2. 创建名为`$AIRFLOW_HOME/config/log_config.py``$AIRFLOW_HOME/config/__init__.py`空文件。
5. 确保已在Airflow中定义Azure Blob存储(Wasb)连接挂钩。 挂钩应具有对`REMOTE_BASE_LOG_FOLDER`定义的Azure Blob存储桶的读写访问权限
3.`airflow/config_templates/airflow_local_settings.py`的内容复制到刚刚在上面的步骤中创建的`log_config.py`文件中
6. 更新`$AIRFLOW_HOME/airflow.cfg`以包含
4. 自定义模板的以下部分
> ```
> remote_logging = True
> logging_config_class = log_config.LOGGING_CONFIG
> remote_log_conn_id = <name of the Azure Blob Storage connection>
>
> ```
7. 重新启动Airflow网络服务器和调度程序,并触发(或等待)新任务执行。
8. 验证日志是否显示在您定义的存储桶中新执行的任务中。
## 将日志写入Google云端存储
```
# wasb buckets should start with "wasb" just to help Airflow select correct handler
REMOTE_BASE_LOG_FOLDER = 'wasb-<whatever you want here>'
请按照以下步骤启用Google云端存储日志记录。
# 重命名DEFAULT_LOGGING_CONFIG为LOGGING CONFIG
LOGGING_CONFIG = ...
```
1. Airflow的日志记录系统需要将自定义.py文件放在`PYTHONPATH` ,以便可以从Airflow导入。 首先创建一个存储配置文件的目录。 建议使用`$AIRFLOW_HOME/config`
5. 确保已在Airflow中定义Azure Blob Storage(Wasb)连接挂钩。挂钩应具有对`REMOTE_BASE_LOG_FOLDER`定义的Azure Blob Storage存储桶的读写访问权限
2. 创建名为`$AIRFLOW_HOME/config/log_config.py``$AIRFLOW_HOME/config/__init__.py`空文件。
6. 更新`$AIRFLOW_HOME/airflow.cfg`以包含:
3.`airflow/config_templates/airflow_local_settings.py`的内容复制到刚刚在上面的步骤中创建的`log_config.py`文件中。
```
remote_logging = True
logging_config_class = log_config.LOGGING_CONFIG
remote_log_conn_id = <name of the Azure Blob Storage connection>
```
4. 自定义模板的以下部分:
7. 重新启动Airflow网络服务器和调度程序,并触发(或等待)新任务执行。
&gt; ```
&gt; # Add this variable to the top of the file. Note the trailing slash.
&gt; GCS_LOG_FOLDER = 'gs://&lt;bucket where logs should be persisted&gt;/'
&gt;
&gt; # Rename DEFAULT_LOGGING_CONFIG to LOGGING CONFIG
&gt; LOGGING_CONFIG = ...
&gt;
&gt; # Add a GCSTaskHandler to the 'handlers' block of the LOGGING_CONFIG variable
&gt; 'gcs.task' : {
&gt; 'class' : 'airflow.utils.log.gcs_task_handler.GCSTaskHandler' ,
&gt; 'formatter' : 'airflow.task' ,
&gt; 'base_log_folder' : os.path.expanduser ( BASE_LOG_FOLDER ) ,
&gt; 'gcs_log_folder' : GCS_LOG_FOLDER,
&gt; 'filename_template' : FILENAME_TEMPLATE,
&gt; } ,
&gt;
&gt; # Update the airflow.task and airflow.task_runner blocks to be 'gcs.task' instead of 'file.task'.
&gt; 'loggers' : {
&gt; 'airflow.task' : {
&gt; 'handlers' : [ 'gcs.task' ] ,
&gt; ...
&gt; } ,
&gt; 'airflow.task_runner' : {
&gt; 'handlers' : [ 'gcs.task' ] ,
&gt; ...
&gt; } ,
&gt; 'airflow' : {
&gt; 'handlers' : [ 'console' ] ,
&gt; ...
&gt; } ,
&gt; }
&gt;
&gt; ```
8. 验证日志是否显示在您定义的存储桶中新执行的任务中。
5. 确保已在Airflow中定义了Google Cloud Platform连接挂钩。 该挂钩应具有对`GCS_LOG_FOLDER`定义的Google Cloud Storage存储桶的读写访问权限。
## 将日志写入Google Cloud Storage
6. 更新`$AIRFLOW_HOME/airflow.cfg`以包含:
请按照以下步骤启用Google Cloud Storage日志记录。
&gt; ```
&gt; task_log_reader = gcs.task
&gt; logging_config_class = log_config.LOGGING_CONFIG
&gt; remote_log_conn_id = &lt;name of the Google cloud platform hook&gt;
&gt;
&gt; ```
要启用此功能,必须按照此示例配置airflow.cfg:
7. 重新启动Airflow网络服务器和调度程序,并触发(或等待)新任务执行。
```
[core]
# Airflow can store logs remotely in AWS S3, Google Cloud Storage or Elastic Search.
# Users must supply an Airflow connection id that provides access to the storage
# location. If remote_logging is set to true, see UPDATING.md for additional
# configuration requirements.
remote_logging = True
remote_base_log_folder = gs://my-bucket/path/to/logs
remote_log_conn_id = MyGCSConn
```
8. 验证日志是否显示在您定义的存储桶中新执行的任务中。
1. 首先安装`gcp_api`安装包,`pip install apache-airflow[gcp_api]`
2. 确保已在Airflow中定义了Google Cloud Platform连接挂钩。该钩子应具有对remote_base_log_folder中上面定义的Google Cloud Storage存储桶的读写访问权限。
3. 重新启动Airflow网络服务器和调度程序,并触发(或等待)新任务执行。
4. 验证日志是否显示在您定义的存储桶中新执行的任务中。
5. 确认Google Cloud Storage查看器在U​​I中正常运行。拉出新执行的任务,并验证您是否看到类似的内容
9. 确认Google Cloud Storage查看器在U​​I中正常运行。 拉出新执行的任务,并验证您是否看到类似的内容:
```
*** Reading remote log from gs://<bucket where logs should be persisted>/example_bash_operator/run_this_last/2017-10-03T00:00:00/16.log.
[2017-10-03 21:57:50,056] {cli.py:377} INFO - Running on host chrisr-00532
[2017-10-03 21:57:50,093] {base_task_runner.py:115} INFO - Running: ['bash', '-c', u'airflow run example_bash_operator run_this_last 2017-10-03T00:00:00 --job_id 47 --raw -sd DAGS_FOLDER/example_dags/example_bash_operator.py']
[2017-10-03 21:57:51,264] {base_task_runner.py:98} INFO - Subtask: [2017-10-03 21:57:51,263] {__init__.py:45} INFO - Using executor SequentialExecutor
[2017-10-03 21:57:51,306] {base_task_runner.py:98} INFO - Subtask: [2017-10-03 21:57:51,306] {models.py:186} INFO - Filling up the DagBag from /airflow/dags/example_dags/example_bash_operator.py
```
&gt; ```
&gt; *** Reading remote log from gs://&lt;bucket where logs should be persisted&gt;/example_bash_operator/run_this_last/2017-10-03T00:00:00/16.log.
&gt; [ 2017 -10-03 21 :57:50,056 ] { cli.py:377 } INFO - Running on host chrisr-00532
&gt; [ 2017 -10-03 21 :57:50,093 ] { base_task_runner.py:115 } INFO - Running: [ 'bash' , '-c' , u 'airflow run example_bash_operator run_this_last 2017-10-03T00:00:00 --job_id 47 --raw -sd DAGS_FOLDER/example_dags/example_bash_operator.py' ]
&gt; [ 2017 -10-03 21 :57:51,264 ] { base_task_runner.py:98 } INFO - Subtask: [ 2017 -10-03 21 :57:51,263 ] { __init__.py:45 } INFO - Using executor SequentialExecutor
&gt; [ 2017 -10-03 21 :57:51,306 ] { base_task_runner.py:98 } INFO - Subtask: [ 2017 -10-03 21 :57:51,306 ] { models.py:186 } INFO - Filling up the DagBag from /airflow/dags/example_dags/example_bash_operator.py
&gt;
&gt; ```
请注意它从远程日志文件中读取的顶行。
请注意,如果您使用旧式airflow.cfg配置方法将日志保存到Google云端存储,则旧的日志将不再在Airflow用户界面中显示,但它们仍将存在于Google云端存储中。 这是一个向后无比的变化。 如果您对此不满意,可以更改`FILENAME_TEMPLATE`以反映旧式日志文件名格式。
\ No newline at end of file
请注意顶行说明了它是从远程日志文件中读取的。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册