-
Notifications
You must be signed in to change notification settings - Fork 329
documentation update and re-organization #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+832
−381
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9c626c5
getting started on resetting the content a bit
heckj caa03e1
document revisions
heckj 1a57d24
initial draft pass complete adding abstracts for all the public types
heckj fdb6a11
fixing a few grammar and execution gaps
heckj a0ff32e
copyedit pass to fix spelling and grammar
heckj 3a8ea8b
fixing the swift-format misses
heckj 3e7a742
removing added dependency used for vetting the content
heckj fd51335
fixing formatting in snippet
heckj b4fc53c
Apply suggestion from @czechboy0
heckj 86a6c1a
Update Sources/Logging/Logging.swift
heckj 03e948d
Update Sources/Logging/Logging.swift
heckj 9850f40
Update Sources/Logging/Logging.swift
heckj 54ca5e1
Update Sources/Logging/Logging.swift
heckj db58cb3
applying wrapping format from feedback
heckj 5b26b77
revising parameter per feedback
heckj 7dea663
removing copy/paste comment from initializer without a factory method…
heckj 69eb15e
Update Sources/Logging/Docs.docc/UnderstandingLoggers.md
heckj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Import the logging API | ||
| import Logging | ||
|
|
||
| // Create a logger with a label | ||
| let logger = Logger(label: "MyLogger") | ||
|
|
||
| // Use it to log messages | ||
| logger.info("Hello World!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # ``Logging/LogHandler`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Sending log messages | ||
|
|
||
| - ``log(level:message:metadata:source:file:function:line:)-8kgt7`` | ||
| - ``log(level:message:metadata:source:file:function:line:)-69pez`` | ||
| - ``log(level:message:metadata:file:function:line:)-89rya`` | ||
| - ``log(level:message:metadata:file:function:line:)-1xdau`` | ||
|
|
||
| ### Updating metadata | ||
|
|
||
| - ``subscript(metadataKey:)`` | ||
|
|
||
| ### Inspecting a log handler | ||
|
|
||
| - ``logLevel`` | ||
| - ``metadata`` | ||
| - ``metadataProvider`` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # ``Logging/Logger/Level`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Log Levels | ||
|
|
||
| - ``trace`` | ||
| - ``debug`` | ||
| - ``info`` | ||
| - ``notice`` | ||
| - ``warning`` | ||
| - ``error`` | ||
| - ``critical`` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # ``Logging/Logger/Message`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Creating a log message | ||
|
|
||
| - ``init(stringLiteral:)`` | ||
|
|
||
| ### Inspecting a log message | ||
|
|
||
| - ``description`` | ||
|
|
15 changes: 15 additions & 0 deletions
15
Sources/Logging/Docs.docc/Reference/Logger-MetadataProvider.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # ``Logging/Logger/MetadataProvider`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Creating a metadata provider | ||
|
|
||
| - ``init(_:)`` | ||
|
|
||
| ### Invoking the provider | ||
|
|
||
| - ``get()`` | ||
|
|
||
| ### Merging metadata | ||
|
|
||
| - ``multiplex(_:)`` |
11 changes: 11 additions & 0 deletions
11
Sources/Logging/Docs.docc/Reference/Logger-MetadataValue.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # ``Logging/Logger/MetadataValue`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Types of metadata values | ||
|
|
||
| - ``string(_:)`` | ||
| - ``stringConvertible(_:)`` | ||
| - ``array(_:)`` | ||
| - ``dictionary(_:)`` | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # ``Logging/Logger`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Creating Loggers | ||
|
|
||
| - ``init(label:)`` | ||
| - ``init(label:metadataProvider:)`` | ||
| - ``init(label:factory:)-9uiy2`` | ||
| - ``init(label:factory:)-6iktu`` | ||
heckj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - ``MetadataProvider`` | ||
|
|
||
| ### Sending trace log messages | ||
|
|
||
| - ``trace(_:metadata:file:function:line:)`` | ||
| - ``trace(_:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Sending debug log messages | ||
| - ``debug(_:metadata:file:function:line:)`` | ||
| - ``debug(_:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Sending info log messages | ||
| - ``info(_:metadata:file:function:line:)`` | ||
| - ``info(_:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Sending notice log messages | ||
| - ``notice(_:metadata:file:function:line:)`` | ||
| - ``notice(_:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Sending warning log messages | ||
| - ``warning(_:metadata:file:function:line:)`` | ||
| - ``warning(_:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Sending error log messages | ||
| - ``error(_:metadata:file:function:line:)`` | ||
| - ``error(_:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Sending critical log messages | ||
| - ``critical(_:metadata:file:function:line:)`` | ||
| - ``critical(_:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Sending general log messages | ||
|
|
||
| - ``log(level:_:metadata:file:function:line:)`` | ||
| - ``log(level:_:metadata:source:file:function:line:)`` | ||
| - ``Level`` | ||
| - ``Message`` | ||
| - ``Metadata`` | ||
|
|
||
| ### Adjusting logger metadata | ||
|
|
||
| - ``subscript(metadataKey:)`` | ||
| - ``MetadataValue`` | ||
|
|
||
| ### Inspecting a logger | ||
|
|
||
| - ``label`` | ||
| - ``logLevel`` | ||
| - ``handler`` | ||
| - ``metadataProvider`` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # ``Logging/LoggingSystem`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Initializing the logging system | ||
|
|
||
| - ``bootstrap(_:)`` | ||
| - ``bootstrap(_:metadataProvider:)`` | ||
|
|
||
| ### Inspecting the logging system | ||
|
|
||
| - ``metadataProvider`` | ||
|
|
22 changes: 22 additions & 0 deletions
22
Sources/Logging/Docs.docc/Reference/MultiplexLogHandler.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # ``Logging/MultiplexLogHandler`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Creating a multiplex log handler | ||
|
|
||
| - ``init(_:)`` | ||
| - ``init(_:metadataProvider:)`` | ||
|
|
||
| ### Sending log messages | ||
|
|
||
| - ``log(level:message:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Updating metadata | ||
|
|
||
| - ``subscript(metadataKey:)`` | ||
|
|
||
| ### Inspecting a log handler | ||
|
|
||
| - ``logLevel`` | ||
| - ``metadata`` | ||
| - ``metadataProvider`` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # ``Logging/StreamLogHandler`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Creating a stream log handler | ||
|
|
||
| - ``standardOutput(label:)`` | ||
| - ``standardOutput(label:metadataProvider:)`` | ||
| - ``standardError(label:)`` | ||
| - ``standardError(label:metadataProvider:)`` | ||
|
|
||
| ### Sending log messages | ||
|
|
||
| - ``log(level:message:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Updating metadata | ||
|
|
||
| - ``subscript(metadataKey:)`` | ||
|
|
||
| ### Inspecting a log handler | ||
|
|
||
| - ``logLevel`` | ||
| - ``metadata`` | ||
| - ``metadataProvider`` |
22 changes: 22 additions & 0 deletions
22
Sources/Logging/Docs.docc/Reference/SwiftLogNoOpLogHandler.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # ``Logging/SwiftLogNoOpLogHandler`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Creating a Swift Log no-op log handler | ||
|
|
||
| - ``init()`` | ||
| - ``init(_:)`` | ||
|
|
||
| ### Sending log messages | ||
|
|
||
| - ``log(level:message:metadata:source:file:function:line:)`` | ||
|
|
||
| ### Updating metadata | ||
|
|
||
| - ``subscript(metadataKey:)`` | ||
|
|
||
| ### Inspecting a log handler | ||
|
|
||
| - ``logLevel`` | ||
| - ``metadata`` | ||
| - ``metadataProvider`` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Understanding Loggers and Log Handlers | ||
|
|
||
| Learn how to create and configure loggers, set log levels, and use metadata to add context to your log messages. | ||
|
|
||
| ## Overview | ||
|
|
||
| Create or retrieve a logger to get an instance for logging messages. | ||
| Log messages have a level that you use to indicate the message's importance. | ||
|
|
||
| SwiftLog defines seven log levels, represented by ``Logger/Level``, ordered from least to | ||
| most severe: | ||
|
|
||
| - ``Logger/Level/trace`` | ||
| - ``Logger/Level/debug`` | ||
| - ``Logger/Level/info`` | ||
| - ``Logger/Level/notice`` | ||
| - ``Logger/Level/warning`` | ||
| - ``Logger/Level/error`` | ||
| - ``Logger/Level/critical`` | ||
|
|
||
| Once a message is sent to a logger, a log handler processes it. | ||
| The app using the logger configures the handler, usually for the environment in which that app runs, processing messages appropriate to that environment. | ||
| If the app doesn't provide its own log handler, SwiftLog defaults to using a ``StreamLogHandler`` that outputs log messages to `STDOUT`. | ||
|
|
||
| ### Loggers | ||
|
|
||
| Loggers are used to emit log messages at different severity levels: | ||
|
|
||
| ```swift | ||
| // Informational message | ||
| logger.info("Processing request") | ||
|
|
||
| // Something went wrong | ||
| logger.error("Houston, we have a problem") | ||
| ``` | ||
|
|
||
| ``Logger`` is a value type with value semantics, meaning that when you modify a | ||
| logger's configuration (like its log level or metadata), it only affects that | ||
| specific logger instance: | ||
|
|
||
| ```swift | ||
| let baseLogger = Logger(label: "MyApp") | ||
|
|
||
| // Create a new logger with different configuration. | ||
| var requestLogger = baseLogger | ||
| requestLogger.logLevel = .debug | ||
| requestLogger[metadataKey: "request-id"] = "\(UUID())" | ||
|
|
||
| // baseLogger is unchanged. It still has default log level and no metadata | ||
| // requestLogger has debug level and request-id metadata. | ||
| ``` | ||
|
|
||
| This value type behavior makes loggers safe to pass between functions and modify | ||
| without unexpected side effects. | ||
|
|
||
| ### Log Levels | ||
|
|
||
| Log levels can be changed per logger without affecting others: | ||
|
|
||
| ```swift | ||
| var logger = Logger(label: "MyLogger") | ||
| logger.logLevel = .debug | ||
| ``` | ||
|
|
||
| For guidance on what level to use for a message, see <doc:001-ChoosingLogLevels>. | ||
|
|
||
| ### Logging Metadata | ||
|
|
||
| Metadata provides contextual information crucial for debugging: | ||
|
|
||
| ```swift | ||
| var logger = Logger(label: "com.example.server") | ||
| logger[metadataKey: "request.id"] = "\(UUID())" | ||
| logger.info("Processing request") | ||
| ``` | ||
|
|
||
| Output: | ||
| ``` | ||
| 2019-03-13T18:30:02+0000 info: request-uuid=F8633013-3DD8-481C-9256-B296E43443ED Processing request | ||
| ``` | ||
|
|
||
| ### Source vs Label | ||
|
|
||
| A ``Logger`` has an immutable `label` that identifies its creator, while each log | ||
| message carries a `source` parameter that identifies where the message originated. | ||
| Use `source` for filtering messages from specific subsystems. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.