github-actions-logger
A logging.Logger subclass that emits GitHub Actions workflow commands when running in CI, and behaves like a normal logger everywhere else.
Installation
pip install github-actions-logger
Or with uv:
uv add github-actions-logger
Requires Python 3.12 or newer.
Usage
from github_actions_logger import Logger
log = Logger("my-app")
log.debug("Cache key: %s", key)
log.info("Deployed")
log.warning("Deprecated option used")
log.error("Build failed")
In GitHub Actions (detected via GITHUB_ACTIONS=true) these print:
::debug::Cache key: abc123
::notice::Deployed
::warning::Deprecated option used
::error::Build failed
Anywhere else, the calls go through standard logging, so handlers, levels and formatters work as usual.
Level mapping
| Method | Workflow command |
|---|---|
debug |
::debug:: |
info |
::notice:: |
warning |
::warning:: |
error, critical, exception |
::error:: |
exception() (or any call with exc_info) appends the traceback to the message.
Annotations
notice, warning and error messages can be attached to a file and line by passing the standard extra argument:
log.warning(
"Unused import",
extra={"title": "Lint", "file": "src/app.py", "line": 12, "end_line": 12, "col": 1, "end_column": 20},
)
::warning title=Lint,file=src/app.py,line=12,endLine=12,col=1,endColumn=20::Unused import
extra key |
Workflow property |
|---|---|
title |
title |
file |
file |
line |
line |
end_line |
endLine |
col |
col |
end_column |
endColumn |
Missing or None keys and unrelated keys are ignored, and debug ignores them entirely since ::debug:: takes no properties. Outside CI, extra becomes attributes on the LogRecord, so a formatter can use it (for example %(file)s:%(line)s).
Grouping log lines
group() returns a context manager that wraps output in a collapsible log group:
with log.group("Install dependencies"):
log.info("Resolving...")
::group::Install dependencies
::notice::Resolving...
::endgroup::
::endgroup:: is emitted even if the block raises. Outside CI, group() does nothing.
Overriding detection
CI detection happens once, when the logger is created. To force it on or off, pass in_ci:
Logger("my-app", in_ci=True) # always emit workflow commands
Logger("my-app", in_ci=False) # always use standard logging
Notes
- In CI, messages are written straight to stdout and bypass the logger's level and handlers. GitHub only displays
::debug::lines when step debug logging is enabled (ACTIONS_STEP_DEBUG). - Create the logger with
Logger(...)directly.logging.setLoggerClass(Logger)pluslogging.getLogger(name)works, but only passesname, soin_cican't be set that way.
Development
uv run pytest
Runs the tests with a coverage report.
Metadata
Release files for github-actions-logger 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| github_actions_logger-0.1.0.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| github_actions_logger-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / github_actions_logger-0.1.0.tar.gz
| Download URL | github_actions_logger-0.1.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
551b7a9a817deec67267e1615dbe0fec0efffc0ef6616b8735090cab569d9fcf
|
|
BLAKE2b-256 checksum How to use checksums |
52be1ea8810fa1c5aab56762087d48b91a7f30b3347e88db6b0a98635e891b20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 17, 2026.
Transparency logRelease files / github_actions_logger-0.1.0-py3-none-any.whl
| Download URL | github_actions_logger-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11dabaa96d56e431171d0171b5e023524cd431bdc2dd21e62e5306c4a7fff413
|
|
BLAKE2b-256 checksum How to use checksums |
8d5589cf62d731d49cffb5701439408b89685fc3d7cb6914f333443ba5e6c98f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 17, 2026.
Transparency log