Skip to main content

log_ctrl

en ja

log_ctrl は、指定したログディレクトリに保存されているログファイルを、grpc_frame を使ってネットワーク越しに参照するためのパッケージです。

ログを書き込む側の DeviceServer やアプリケーションにはログ取得 RPC を追加しません。log_ctrl は既存のログファイルを read-only で参照する独立した gRPC サーバーとして動作します。

application / DeviceServer
        │
        │ write
        ▼
C:\opt\ese774\log
├── cobotta4_server.log
├── cobotta4_server.log.2026-04-06
├── cobotta4_server2.log
└── cobotta4_server2.log.2026-06-16
        ▲
        │ read only
        │
     LogCtrl
        │
        ▼
 log gRPC server
        │
        ▼
DeviceProxy("log", ...)

ログ名

log_ctrl では、.log より前の部分を log_name と呼びます。

cobotta4_server.log
^^^^^^^^^^^^^^^
   log_name

ローテーション済みログは次の形式です。

<log_name>.log.YYYY-MM-DD

log_name は DeviceServer 名やデバイスクラス名と一致する必要はありません。log_ctrl はファイル名として存在する log_name をそのまま扱います。

主な機能

  • log_names() : 実在するログファイルから log_name 一覧を取得
  • dates(log_name) : 指定した log_name のローテーション日付一覧を取得
  • exists(log_name, date=None) : 現在ログまたは指定日ログの存在確認
  • tail(log_name, lines=100, date=None) : ログ末尾を文字列で取得
  • raw_files() : ログディレクトリ以下の全ファイルを相対パスで列挙
  • read(log_name, date=None) : ログファイル本体を bytes で取得
  • read_raw(relative_path) : raw_files() で確認した任意ファイルを bytes で取得

大きなログファイルは grpc_frame の StreamCall を使ってチャンク転送します。利用側ではストリーム処理を直接扱う必要はなく、read() / read_raw() が受信したチャンクを結合して bytes として返します。

インストール

grpc_frame を利用可能な環境でインストールします。

python -m pip install .

開発時は次のように editable install できます。

python -m pip install -e .

LogServer の起動

from log_ctrl.server_grpc import log_grpc_server

GRPC_HOST = "0.0.0.0"
GRPC_PORT = 50060
LOG_DIR = r"C:\opt\ese774\log"

log_grpc_server(
    grpc_host=GRPC_HOST,
    grpc_port=GRPC_PORT,
    log_dir=LOG_DIR,
)

logger を省略した場合は標準の logging が使用されます。既存の logger を使用する場合は logger= で渡せます。

クライアント

grpc_frame の透過クライアントとして DeviceProxy を使用します。

from log_ctrl.server_grpc import DeviceProxy

client = DeviceProxy(
    "log",
    server_ip="127.0.0.1",
    server_port=50060,
    set_timeout_sec=10.0,
    async_mode=False,
)

try:
    log_names = client.log_names()
    print(log_names)

    if len(log_names) > 0:
        log_name = log_names[0]

        print(client.dates(log_name))

        if client.exists(log_name):
            data = client.read(log_name)
            print(len(data))

finally:
    client.close()

log_names() で返される名前は、現在の <log_name>.log が存在する名前だけとは限りません。ローテーション済みファイルだけが残っている場合も一覧に含まれます。現在ログを読む前に必要に応じて exists(log_name) を確認してください。

API

client.log_names()
client.dates(log_name)

client.exists(log_name)
client.exists(log_name, date="2026-04-06")

client.tail(log_name, lines=100)
client.tail(log_name, lines=100, date="2026-04-06")

client.raw_files()

client.read(log_name)
client.read(log_name, date="2026-04-06")

client.read_raw("cobotta4_server.log.2026-04-06")

read() と read_raw() の戻り値は bytes です。ログを文字列として扱う場合は、使用している文字コードに合わせてクライアント側で decode します。

text = client.read(log_name).decode("utf-8")

tail() はサーバー側で設定された encoding を使って decode され、str を返します。

ドキュメント

Sphinx 用文書は docs/ にあります。

  • docs/index.md
  • docs/quickstart.md
  • docs/usage.md
  • docs/rotation.md
  • docs/architecture.md

License

LICENSE を参照してください。

Metadata

Release files for log-ctrl 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for log-ctrl 0.0.2
File Size Uploaded Provenance
log_ctrl-0.0.2.tar.gz 19.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for log-ctrl 0.0.2
File Interpreter ABI Platform
log_ctrl-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.9 kB

Release files / log_ctrl-0.0.2.tar.gz

Download URL log_ctrl-0.0.2.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9b464db844a1a29694c9c919f80c396a13323299b6ff3cd7cab81d9bf0cec3ef
BLAKE2b-256 checksum
How to use checksums
9f767bd7323c49dff164dd33416fb8b74d97b78f4a80f63988473907d33808ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / log_ctrl-0.0.2-py3-none-any.whl

Download URL log_ctrl-0.0.2-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3be63b7987da878fa7ae49919905ed6805137476d9b797e2b0d83b2bc1f1a6a0
BLAKE2b-256 checksum
How to use checksums
acd894f650f94550b9f8f29c79f6bb4a5857a7909912f62d62307cf0c9e83367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for log-ctrl 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for log_ctrl-0.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page