返回介绍

3.8.7. Logs connector

发布于 2023-09-20 23:50:40 字数 7231 浏览 0 评论 0 收藏 0

Caution

Buildbot no longer supports Python 2.7 on the Buildbot master.

3.8.7. Logs connector

class buildbot.db.logs.LogsConnectorComponent

This class handles log data. Build steps can have zero or more logs. Logs are uniquely identified by name within a step.

Information about a log, apart from its contents, is represented as a dictionary with the following keys, referred to as a logdict:

  • id (log ID, globally unique)

  • stepid (step ID, indicating the containing step)

  • name free-form name of this log

  • slug (50-identifier for the log, unique within the step)

  • complete (true if the log is complete and will not receive more lines)

  • num_lines (number of lines in the log)

  • type (log type; see below)

Each log has a type that describes how to interpret its contents. See the logchunk resource type for details.

A log contains a sequence of newline-separated lines of unicode. Log line numbering is zero-based.

Each line must be less than 64k when encoded in UTF-8. Longer lines will be truncated, and a warning will be logged.

Lines are stored internally in “chunks”, and optionally compressed, but the implementation hides these details from callers.

getLog(logid)
Parameters:

logid (integer) – ID of the requested log

Returns:

logdict via Deferred

Get a log, identified by logid.

getLogBySlug(stepid, slug)
Parameters:
  • stepid (integer) – ID of the step containing this log

  • slug – slug of the logfile to retrieve

Returns:

logdict via Deferred

Get a log, identified by name within the given step.

getLogs(stepid)
Parameters:

stepid (integer) – ID of the step containing the desired logs

Returns:

list of logdicts via Deferred

Get all logs within the given step.

getLogLines(logid, first_line, last_line)
Parameters:
  • logid (integer) – ID of the log

  • first_line – first line to return

  • last_line – last line to return

Returns:

see below

Get a subset of lines for a logfile.

The return value, via Deferred, is a concatenation of newline-terminated strings. If the requested last line is beyond the end of the logfile, only existing lines will be included. If the log does not exist, or has no associated lines, this method returns an empty string.

addLog(stepid, name, type)
Parameters:
  • stepid (integer) – ID of the step containing this log

  • name (string) – name of the logfile

  • slug (50-character identifier) – slug (unique identifier) of the logfile

  • type (string) – log type (see above)

Raises:

KeyError – if a log with the given slug already exists in the step

Returns:

ID of the new log, via Deferred

Add a new log file to the given step.

appendLog(logid, content)
Parameters:
  • logid (integer) – ID of the requested log

  • content (string) – new content to be appended to the log

Returns:

tuple of first and last line numbers in the new chunk, via Deferred

Append content to an existing log. The content must end with a newline. If the given log does not exist, the method will silently do nothing.

It is not safe to call this method more than once simultaneously for the same logid.

finishLog(logid)
Parameters:

logid (integer) – ID of the log to mark complete

Returns:

Deferred

Mark a log as complete.

Note that no checking for completeness is performed when appending to a log. It is up to the caller to avoid further calls to appendLog after finishLog.

compressLog(logid)
Parameters:

logid (integer) – ID of the log to compress

Returns:

Deferred

Compress the given log. This method performs internal optimizations on a log’s chunks to reduce the space used and make read operations more efficient. It should only be called for finished logs. This method may take some time to complete.

deleteOldLogChunks(older_than_timestamp)
Parameters:

older_than_timestamp (integer) – the logs whose step’s started_at is older than older_than_timestamp will be deleted.

Returns:

Deferred

Delete old logchunks (helper for the logHorizon policy). Old logs have their logchunks deleted from the database, but they keep their num_lines metadata. They have their types changed to ‘d’, so that the UI can display something meaningful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文