Skip to content

Commit 30bc2f6

Browse files
Amend standard output logging ADR (#587)
* Amend standard output logging ADR * Apply suggestions from code review Co-authored-by: Matt Bishop <[email protected]> --------- Co-authored-by: Matt Bishop <[email protected]>
1 parent 826eeb7 commit 30bc2f6

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

docs/architecture/adr/0021-standard-output-logging.md

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,17 @@ Chosen option: **Consolidate logging providers**.
4545

4646
Given long-term plans to adopt a more flexible shared (hosting extensions) library that can be used
4747
across services either as a project (server monolith) reference or NuGet package (and as a reference
48-
architecture), using Serilog as a way to extend native logging capabilities is beneficial. Details
49-
around how Serilog is implemented along with its advanced inputs and outputs can be extracted away
50-
into the shared library and driven at consuming applications via configuration.
48+
architecture), using `Microsoft.Extensions.Logging` as the core way to do logging is beneficial. The
49+
out-of-the-box defaults are generally good enough for local and self-hosted usage. Our shared
50+
library will be able to have automatic defaults for our cloud usage though, namely using JSON
51+
logging along with including scopes. It also gives us a built-in way to be able to override any of
52+
these details through any of our configuration providers.
53+
54+
We will continue to offer file based logging through Serilog but will be able to reduce our NuGet
55+
packages to only `Serilog.Extensions.Logging.File`. In an effort to reduce our own upkeep and allow
56+
maximal customization we will be deprecating the log settings in `GlobalSettings`; instead we will
57+
refer to [`Serilog` documentation][serilogconfig] to offer both more options and more standard
58+
naming.
5159

5260
### Positive Consequences
5361

@@ -56,6 +64,9 @@ into the shared library and driven at consuming applications via configuration.
5664
- Elimination of several third-party dependencies and their maintenance, as well as global settings.
5765
- No new dependencies that are merely aligned with the Bitwarden-specific cloud and its service
5866
providers.
67+
- Allow self-host customers to configure the console log format.
68+
- Not require any new configuration for our cloud that is currently using
69+
`Microsoft.Extensions.Logging`.
5970

6071
### Negative Consequences
6172

@@ -72,13 +83,16 @@ be removed:
7283
- Sentry
7384
- Syslog
7485

75-
The remaining sinks -- core functionality of Serilog -- will continue to be supported:
86+
The `File` sink will continue to be supported with the following configuration layout:
7687

77-
- Console
78-
- File
79-
80-
While the Serilog [console sink][serilogconsole] is currently an implicit dependency with what's
81-
provided for ASP.NET Core, it will be explicitly referenced.
88+
```json
89+
{
90+
"Logging": {
91+
"PathFormat": "logs/{Date}.txt",
92+
"FileSizeLimitBytes": 4096
93+
}
94+
}
95+
```
8296

8397
Solutions exist for users to shift processing of logs for the removed sinks to standard output or
8498
file and retain their integration. Admin Portal users can similarly continue to use CosmosDb for log
@@ -87,34 +101,36 @@ should in essentially all cases be able to receive and process standard output l
87101

88102
Cloud installations -- including Bitwarden's own -- will shift to configuration via environment
89103
variables or otherwise to utilize structured standard output logs for processing explicitly with
90-
[Serilog configuration][serilogconfig] e.g.:
104+
[`Microsoft.Extensions.Logging` configuration][melconfig] this will also allow online updates if the
105+
configuration is done through a provider that supports change detection e.g.:
91106

92107
```json
93108
{
94-
"Serilog": {
95-
"Using": ["Serilog.Sinks.Console"],
96-
"MinimumLevel": "Verbose",
97-
"WriteTo": [{ "Name": "Console" }],
98-
"Enrich": ["FromLogContext"],
99-
"Properties": {
100-
"Project": "BitwardenProjectName"
109+
"Logging": {
110+
"LogLevel": {
111+
"Default": "Information"
112+
},
113+
"Console": {
114+
"FormatterName": "json",
115+
"FormatterOptions": {
116+
"SingleLine": true,
117+
"IncludeScopes": true,
118+
"TimestampFormat": "HH:mm:ss ",
119+
"UseUtcTimestamp": true,
120+
"JsonWriterOptions": {
121+
"Indented": true
122+
}
123+
}
101124
}
102125
}
103126
}
104127
```
105128

106-
This will allow better usage of `appsettings.json` and a richer developer experience. Existing
107-
built-in [.NET Core logging][netcorelogging] will continue to be available if desired, but the
108-
recommendation will be to move to a Serilog configuration.
109-
110129
Code cleanup will be performed around Serilog usage, such as:
111130

112131
- Removal of overuse of inclusion predicates that complicate (or sometimes block) effective log
113132
output, for example in the uses of `AddSerilog` in place today at each consuming application.
114-
- Alignment with .NET Core and Serilog best practices on [initialization][seriloginit] and usage of
115-
Serilog itself.
116-
- Improvements in logging initialization reliability and working with configuration issues, as well
117-
as more resilient tear-down when a component stops / ends.
133+
- Reading file sink config from the `Logging` configuration section.
118134
- Removal of the above-deprecated sinks, in the final release of the support window.
119135

120136
Logging functionality will be moved to a new shared library -- separate from the core project -- as
@@ -125,7 +141,7 @@ benefits.
125141
[serilog]: https://serilog.net/
126142
[dd]: https://www.datadoghq.com/
127143
[ddsink]: https://www.nuget.org/packages/serilog.sinks.datadog.logs
128-
[serilogconsole]: https://www.nuget.org/packages/serilog.sinks.console
129-
[serilogconfig]: https://www.nuget.org/packages/Serilog.Settings.Configuration/
130-
[netcorelogging]: https://learn.microsoft.com/en-us/dotnet/core/extensions/logging
131-
[seriloginit]: https://github.com/serilog/serilog-aspnetcore#two-stage-initialization
144+
[serilogconfig]:
145+
https://github.com/serilog/serilog-extensions-logging-file?tab=readme-ov-file#appsettingsjson-configuration
146+
[melconfig]:
147+
https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line#configure-logging

0 commit comments

Comments
 (0)