Skip to content

Commit 74c50ae

Browse files
authored
feat: Store log references in structured fields
1 parent 7e21ab9 commit 74c50ae

21 files changed

+1696
-329
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ jobs:
6565
- name: Setup | Rust Nightly
6666
run: "rustup install nightly && rustup default nightly"
6767
- name: Setup | LLVM Tooling
68-
run: "rustup component add llvm-tools-preview"
68+
run: "rustup component add llvm-tools-preview --toolchain nightly"
6969
- name: Setup | LLVM helper
70-
run: "cargo install cargo-binutils && rustup component add llvm-tools-preview"
70+
run: "cargo install cargo-binutils && cargo install cargo-llvm-cov"
7171
- name: Tests | App
72-
run: './.github/workflows/test_with_coverage.bash "$(pwd)" &> ./small_test_coverage_report.txt && cat ./small_test_coverage_report.txt'
72+
run: './.github/workflows/test_with_coverage.bash "$(pwd)" &> ./test_coverage_report.txt && cat ./test_coverage_report.txt'
7373
- name: Clean artifacts from test | App
7474
run: 'rm -rf ./target/*'
7575
- name: Create build environment | App
@@ -79,8 +79,8 @@ jobs:
7979
- name: Store code coverage report | App
8080
uses: actions/upload-artifact@v3
8181
with:
82-
name: small_test_coverage_report
83-
path: small_test_coverage_report.txt
82+
name: test_coverage_report
83+
path: test_coverage_report.txt
8484
retention-days: 7
8585
- name: Store debug output | App
8686
uses: actions/upload-artifact@v3

.github/workflows/test_with_coverage.bash

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,8 @@ trap on_exit EXIT
2525

2626
cd "${PROJ_DIR}" || exit 2
2727

28-
scratchpad="$(mktemp -d)"
29-
printf "%s\n" "Profiling artefacts in ${scratchpad}"
30-
31-
RUSTFLAGS="-C instrument-coverage" LLVM_PROFILE_FILE="${scratchpad}/profiler-%m.profraw" cargo test --tests || exit 3
32-
33-
prof_out_file="${scratchpad}/profiler.profdata"
34-
rust-profdata merge -sparse ${scratchpad}/*.profraw -o "${prof_out_file}" || exit 4
35-
36-
rust-cov report \
37-
$( \
38-
for file in \
39-
$( \
40-
RUSTFLAGS="-C instrument-coverage" \
41-
cargo test --tests --no-run --message-format=json \
42-
| jq -r "select(.profile.test == true) | .filenames[]" \
43-
| grep -v dSYM - \
44-
); \
45-
do \
46-
printf "%s %s " -object $file; \
47-
done \
48-
) \
49-
--instr-profile="${prof_out_file}" --summary-only --ignore-filename-regex='/.cargo/registry' || exit 5
28+
# Generate a plain text report for easy consumption in stdout
29+
cargo llvm-cov || exit 3
30+
31+
# Generate formatted HTML report (it will be stored in target/llvm-cov/html
32+
cargo llvm-cov report --html || exit 4

Breadlog.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# If you would like to recalculate the next reference from your code, delete this file and
33
# run Breadlog.
44

5-
next_reference_id: 35
5+
next_reference_id: 36

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ complex text parsing required.
1515
source/getting-started
1616
source/configuration
1717
source/running-breadlog
18-
source/excluding-statements
18+
source/directives
1919
source/known-limitations
2020
source/using-log-references
2121

docs/source/configuration.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ configuration options.
2727
# Required. Configuration stanza for Rust code.
2828
rust:
2929
30+
# Optional, default = false. If true, causes Breadlog to look for and
31+
# insert references in the "structured" arguments to log statements.
32+
# Note that generated code requires use of the "kv" feature with the log
33+
# crate.
34+
#
35+
# See https://docs.rs/log/latest/log/kv/index.html for more details.
36+
structured: false
37+
3038
# Required. Detail about the macros and their containing modules used in your
3139
# code for logging. Breadlog assumes use of the log crate
3240
# (https://docs.rs/log/latest/log/), and this example configuration specifies

docs/source/directives.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Directives
2+
==========
3+
4+
Directives provide ways to modify Breadlog behaviour from within your code
5+
using comments.
6+
7+
Disable use of structured logging
8+
---------------------------------
9+
10+
When using structured logging there may be some situations where you still
11+
want a log statement to contain a reference in its log message, rather than
12+
as a key-value pair.
13+
14+
In these scenarios, add a comment to the line before the corresponding
15+
statement with the text ``breadlog:no-kvp``.
16+
17+
For example:
18+
19+
.. code-block:: rust
20+
21+
// breadlog:no-kvp
22+
info!("[ref: 123] This log message will contain the reference, even when structured logging is on.");
23+
24+
Ignore log statements
25+
---------------------
26+
27+
If you'd like Breadlog to ignore particular log statements, add a comment to
28+
the line before the statement with the text ``breadlog:ignore``.
29+
30+
For example:
31+
32+
.. code-block:: rust
33+
34+
// breadlog:ignore
35+
info!("This log statement will be ignored by Breadlog.");
36+
37+

docs/source/excluding-statements.rst

Lines changed: 0 additions & 12 deletions
This file was deleted.

docs/source/getting-started.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Step 2: Configuring a repository
4040
---
4141
source_dir: <RELATIVE SOURCE DIRECTORY>
4242
rust:
43+
structured: false
4344
log_macros:
4445
- module: log
4546
name: info
@@ -58,6 +59,10 @@ Step 2: Configuring a repository
5859
This configuration assumes you're using the `Rust log crate <https://crates.io/crates/log>`_
5960
for logging in your code.
6061

62+
If you're using structured logging (the "kv" feature), set ``structured`` to
63+
``true`` and Breadlog will maintain references as key-value pairs rather than
64+
message text.
65+
6166
Step 3: Running Breadlog for the first time
6267
-------------------------------------------
6368

@@ -104,7 +109,7 @@ references in check mode.
104109

105110
If you'd like Breadlog to ignore a particular log statement, add a comment
106111
to the line before the statement with the text ``breadlog:ignore``. For
107-
more details, see :doc:`excluding-statements`.
112+
more details, see :doc:`directives`.
108113

109114
2. Once you're happy with the output, you can run Breadlog in code generation
110115
mode (without the ``--check`` flag). This will modify your code, inserting

docs/source/using-log-references.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Using Log References
44
Extracting references from log messages
55
---------------------------------------
66

7+
If you're not using structured logging, you'll need to extract references
8+
from log message text through configuration of a log ingestion tool
9+
(such as `Vector <https://vector.dev/guides/level-up/transformation/>`_).
10+
711
References can be extracted from log messages using the following regular
812
expression:
913

0 commit comments

Comments
 (0)