百度智能云

All Product Document

          Log Service

          LogRecord Operations

          Push LogRecord

          Support bulk pushing of log records to the BLS platform. The log record format can be either TEXT or JSON. For TEXT log records, logs remain unprocessed; for JSON log records, JSON fields are automatically identified (only first-level fields are currently supported, nested fields are not yet supported).

          To upload both specific fields extracted from processing and the raw log text, you can use JSON format, including the raw log text as part of JSON (@raw as the key and the raw log text as the value). When processing @raw, BLS will interpret its content as the raw log text.

          Use the following code to bulk push JSON log records to the specified log stream within the specified LogStore.

          // Push JSON logrecord
          pushLogRecordRequest := PushLogRecordRequest{
              Project:       "default",
              LogStoreName:  "test,
              LogStreamName: "json-logStream",
              LogType:       "JSON",
              LogRecords: []api.LogRecord{
                  {
                      Message:   "{\"@raw\": \"raw text\", \"level\": \"info\"}",
                      Timestamp: time.Now().UnixMilli(),
                  },
              },
          }
           // Specify the logrecord type to JSON, and push the logrecord to json-logstream in logstore demo
           // If this logstream is unavailable, create a logstream automatically
          err = BLS_CLIENT.PushLogRecordV2(pushLogRecordRequest)
          if err != nil {
            fmt.Println("Push logRecords failed: ", err)
          } else {
            fmt.Println("Push logRecords success")
          }

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document Push Logrecord

          View the specified logrecord

          With following codes, view the logrecords in the specified logstream, and obtain the recent logrecord contents or the time range of use for filtering.

          pullLogRecordRequest := PullLogRecordRequest{
              Project:       "default",
              LogStoreName:  "test",
              StartDateTime: time.Now().Add(-10 * time.Minute).UTC().Format("2006-01-02T15:04:05Z"),
              EndDateTime:   time.Now().UTC().Format("2006-01-02T15:04:05Z"),
          }
          res, err := BLS_CLIENT.PullLogRecordV2(pullLogRecordRequest)
          if err != nil {
            fmt.Println("Pull logRecord failed: ", err)
          } else {
            fmt.Println("LogRecords result: ", res)
          }

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document Pull Logrecord

          Query the specified logrecord

          Users can search or analyze data in a specified logstore by submitting a query. Only one logstore can be queried at a time.

          Query statements support three formats, such as:

          • match search statement: it is required to enable the full-text index or field-level index and search the log contents according to the conditions, for example:match method:GET and status >= 400
          • SQL statement: execute SQL statements, for example: select * limit 10
          • match search statement| SQL statement: it is required to enable the full-text index or field-level index and execute SQL statements on the result set that meets the search conditions, with the search statement separated from the SQL statement by a vertical line, for example: match method:GET and status >= 400 | select host, count(*) group by host

          Query related restrictions are as follows:

          • The maximum number of query concurrency supported by each account is 15
          • Limit the size of the returned result set to a maximum of 1 MB or 1,000 records.

          For search syntax, please refer to Search Syntax

          SQL statements may not contain from clauses, and syntax details may refer to SQL Syntax

          Use the following code to query log records that satisfy specified conditions within the desired LogStore.

          queryLogRecordRequest := QueryLogRecordRequest{
              Project:       "default",
              LogStoreName:  "test",
              Query:         "match *",
              StartDateTime: time.Now().Add(-20 * time.Second).UTC().Format("2006-01-02T15:04:05Z"),
              EndDateTime:   time.Now().UTC().Format("2006-01-02T15:04:05Z"),
          }
          res, err := BLS_CLIENT.QueryLogRecordV2(queryLogRecordRequest)
          if err != nil {
            fmt.Println("Query logRecord failed: ", err)
          } else {
            fmt.Println("LogRecords result: ", res)
          }

          Prompt:

          • Detailed parameter configuration and restrictions may refer to BLS API document QueryLogRecord
          Previous
          Index Operations
          Next
          LogStream Operations