You can use the rsyslog and syslog-ng utilities to collect logs. After the logs are collected, you can use the syslog protocol to upload the logs to Log Service. This topic describes how to upload logs to Log Service by using the syslog protocol.
Limits
- Syslog logs must be stored based on the RFC 5424 protocol.
- The maximum size of each log is 64 KB.
- Transport Layer Security (TLS) 1.2 must be used to ensure the security of data transmission.
Configurations
If you upload logs by using the syslog protocol, you must specify the endpoint to
which you want to upload the logs. The address is in the <Project name>.<Log Service endpoint>:<Syslog protocol port number>
format. Example: test-project-1.cn-hangzhou-intranet.log.aliyuncs.com:10009. Specify an endpoint based on the region where your Log Service project resides.
For more information, see Endpoints. The syslog port is 10009. You must also specify a Log Service project, a Logstore,
and an AccessKey pair in the STRUCTURED-DATA field. The following table describes
the parameters.
Parameter | Description | Example |
---|---|---|
STRUCTURED-DATA | The value is set to Logservice. | Logservice |
Project | The name of a project. Before you can collect logs, you must create a project. For more information, see Create a project. | test-project-1 |
Logstore | The name of a Logstore. Before you can collect logs, you must create a Logstore. For more information, see Create a Logstore. | test-logstore-1 |
access-key-id | The AccessKey ID that is used to access Log Service. We recommend that you use the AccessKey pair of a RAM user. For more information, see Create a RAM user and authorize the RAM user to access Log Service. | LT****9k |
access-key-secret | The AccessKey secret that is used to access Log Service. We recommend that you use the AccessKey pair of a RAM user. For more information, see Create a RAM user and authorize the RAM user to access Log Service. | Wp****bA |
Example 1: Use the rsyslog utility to upload syslog logs to Log Service
Example 2: Use the syslog-ng utility to upload syslog logs to Log Service
Sample logs
After you upload logs to Log Service, you must configure indexes for the logs. Then, you can view the logs in the Log Service console. For more information, see Configure indexes.

Log field | Description |
---|---|
__source__ | The hostname in the raw log. |
__topic__ | The value is set to syslog-forwarder. |
__facility__ | The facility information, such as the information of the device and module. |
__program__ | The name of the process. |
__serverity__ | The severity level of the syslog log. |
__priority__ | The priority of the syslog log. |
__unixtimestamp__ | The UNIX timestamp of the raw log. Unit: nanoseconds. |
content | The msg field in the raw log. |
FAQ
- How do I simulate log uploading?
You can use Netcat to simulate log uploading. This way, you can check whether the network connection is normal and whether the AccessKey pair is authorized to send syslog logs.
- Log on to the server on which you want to simulate log uploading.
- Run the following command to install Netcat:
sudo yum install nmap-ncat
- Run the following command to connect to Log Service:
ncat --ssl <yourProject>.<yourEndpoint> 10009
Example:ncat --ssl test-project-1.cn-hangzhou.log.aliyuncs.com 10009
- Netcat does not check whether network connections are interrupted. After you run a
ncat command, enter the information that you want to send and press the Enter key in 30
seconds.
<34>1 2019-03-28T03:00:15.003Z mymachine.example.com su - ID47 [logservice project="<yourProject>" logstore="<yourLogstore>" access-key-id="<yourAccessKeyID>" access-key-secret="<yourAccessKeySecret>"] this is a test message
Example:<34>1 2019-03-28T03:00:15.003Z mymachine.example.com su - ID47 [logservice project="trace-doc-test" logstore="doc-test-001-logs" access-key-id="LTAI4***" access-key-secret="HfJEw***"] this is a test message
- After you send the syslog log, you can preview the log in the Log Service console.
For more information, see Preview logs.
- What do I do if logs fail to be uploaded?
Troubleshoot the failure based on the error message. For more information, see How do I view Logtail collection errors?.
- How do I view rsyslog error logs?
You can run the vim command to view rsyslog error logs. By default, rsyslog error logs are stored in the /var/log/message directory.
- Error message 1
dlopen: /usr/lib64/rsyslog/lmnsd_gtls.so: cannot open shared object file: No such file or directory
This error message is returned because the rsyslog-gnutls module is not installed. You can run the sudo apt-get install rsyslog-gnutls command or sudo yum install rsyslog-gnutls command to install the module. After you install the module, restart the rsyslog utility.
- Error message 2
unexpected GnuTLS error -53 - this could be caused by a broken connection. GnuTLS reports:Error in the push function
This error message is returned because the TCP connection is terminated because no actions are performed for a long period of time. You can ignore this error because rsyslog re-establishes the connection.
- Error message 1
- How do I view syslog-ng error logs?
You can run the systemctl status syslog-ng.service command or journalctl-xe command to view syslog-ng error logs. By default, syslog-ng error logs are stored in journal logs.
If the following error message is returned, check whether the format of the configuration file is valid or whether configuration conflicts exist. For example, you cannot configure multipleinternal()
sources.Job for syslog-ng.service failed because the control process exited with error code. See "systemctl status syslog-ng.service" and "journalctl -xe" for details