Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Arti
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jill
Arti
Commits
b8791256
Commit
b8791256
authored
2 years ago
by
Nick Mathewson
Browse files
Options
Downloads
Patches
Plain Diff
Disable safe-logging when logging to console.
parent
7e34692a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
crates/arti/src/logging.rs
+30
-1
30 additions, 1 deletion
crates/arti/src/logging.rs
with
30 additions
and
1 deletion
crates/arti/src/logging.rs
+
30
−
1
View file @
b8791256
...
...
@@ -145,6 +145,28 @@ fn filt_from_opt_str(s: &Option<String>, source: &str) -> Result<Option<Targets>
})
}
/// Helper to disable safe-logging when formatting an event to be logged to the
/// console.
struct
FormatWithSafeLoggingSuppressed
<
F
>
{
/// An inner formatting type that does the actual formatting.
inner
:
F
,
}
impl
<
S
,
N
,
F
>
fmt
::
FormatEvent
<
S
,
N
>
for
FormatWithSafeLoggingSuppressed
<
F
>
where
F
:
fmt
::
FormatEvent
<
S
,
N
>
,
N
:
for
<
'writer
>
fmt
::
FormatFields
<
'writer
>
+
'static
,
S
:
Subscriber
+
for
<
'span
>
tracing_subscriber
::
registry
::
LookupSpan
<
'span
>
,
{
fn
format_event
(
&
self
,
ctx
:
&
fmt
::
FmtContext
<
'_
,
S
,
N
>
,
writer
:
fmt
::
format
::
Writer
<
'_
>
,
event
:
&
tracing
::
Event
<
'_
>
,
)
->
std
::
fmt
::
Result
{
safelog
::
with_safe_logging_suppressed
(||
self
.inner
.format_event
(
ctx
,
writer
,
event
))
}
}
/// Try to construct a tracing [`Layer`] for logging to stdout.
fn
console_layer
<
S
>
(
config
:
&
LoggingConfig
,
cli
:
Option
<&
str
>
)
->
Result
<
impl
Layer
<
S
>>
where
...
...
@@ -154,7 +176,14 @@ where
.map
(|
s
|
filt_from_str_verbose
(
s
,
"--log-level command line parameter"
))
.or_else
(||
filt_from_opt_str
(
&
config
.console
,
"logging.console"
)
.transpose
())
.unwrap_or_else
(||
Ok
(
Targets
::
from_str
(
"debug"
)
.expect
(
"bad default"
)))
?
;
Ok
(
fmt
::
Layer
::
default
()
.with_filter
(
filter
))
// We suppress safe logging when formatting messages for the console,
// which we assume to be volatile.
let
format
=
FormatWithSafeLoggingSuppressed
{
inner
:
fmt
::
format
(),
};
Ok
(
fmt
::
Layer
::
default
()
.event_format
(
format
)
.with_filter
(
filter
))
}
/// Try to construct a tracing [`Layer`] for logging to journald, if one is
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment