mirror of
https://github.com/apple/swift-log
synced 2026-11-24 03:47:49 +00:00
306 lines
16 KiB
HTML
306 lines
16 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<title>Structures Reference</title>
|
||
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
|
||
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
|
||
<meta charset="utf-8">
|
||
<script src="js/jquery.min.js" defer></script>
|
||
<script src="js/jazzy.js" defer></script>
|
||
|
||
<script src="js/lunr.min.js" defer></script>
|
||
<script src="js/typeahead.jquery.js" defer></script>
|
||
<script src="js/jazzy.search.js" defer></script>
|
||
</head>
|
||
<body>
|
||
|
||
<a name="//apple_ref/swift/Section/Structures" class="dashAnchor"></a>
|
||
|
||
<a title="Structures Reference"></a>
|
||
|
||
<header class="header">
|
||
<p class="header-col header-col--primary">
|
||
<a class="header-link" href="index.html">
|
||
Logging 1.4.2 Docs
|
||
</a>
|
||
(81% documented)
|
||
</p>
|
||
|
||
<div class="header-col--secondary">
|
||
<form role="search" action="search.json">
|
||
<input type="text" placeholder="Search documentation" data-typeahead>
|
||
</form>
|
||
</div>
|
||
|
||
<p class="header-col header-col--secondary">
|
||
<a class="header-link" href="https://github.com/apple/swift-log">
|
||
<img class="header-icon" src="img/gh.png" alt="GitHub"/>
|
||
View on GitHub
|
||
</a>
|
||
</p>
|
||
|
||
<p class="header-col header-col--secondary">
|
||
<a class="header-link" href="dash-feed://https%3A%2F%2Fapple.github.io%2Fswift-log%2Fdocs%2F1.4.2%2FLogging%2Fdocsets%2FLogging.xml">
|
||
<img class="header-icon" src="img/dash.png" alt="Dash"/>
|
||
Install in Dash
|
||
</a>
|
||
</p>
|
||
</header>
|
||
|
||
<p class="breadcrumbs">
|
||
<a class="breadcrumb" href="index.html">Logging Reference</a>
|
||
<img class="carat" src="img/carat.png" alt=""/>
|
||
Structures Reference
|
||
</p>
|
||
|
||
<div class="content-wrapper">
|
||
<nav class="navigation">
|
||
<ul class="nav-groups">
|
||
<li class="nav-group-name">
|
||
<a class="nav-group-name-link" href="Enums.html">Enumerations</a>
|
||
<ul class="nav-group-tasks">
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Enums/LoggingSystem.html">LoggingSystem</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="nav-group-name">
|
||
<a class="nav-group-name-link" href="Protocols.html">Protocols</a>
|
||
<ul class="nav-group-tasks">
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Protocols/LogHandler.html">LogHandler</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="nav-group-name">
|
||
<a class="nav-group-name-link" href="Structs.html">Structures</a>
|
||
<ul class="nav-group-tasks">
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Structs/Logger.html">Logger</a>
|
||
</li>
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Structs/Logger/MetadataValue.html">– MetadataValue</a>
|
||
</li>
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Structs/Logger/Level.html">– Level</a>
|
||
</li>
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Structs/Logger/Message.html">– Message</a>
|
||
</li>
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Structs/MultiplexLogHandler.html">MultiplexLogHandler</a>
|
||
</li>
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Structs/StreamLogHandler.html">StreamLogHandler</a>
|
||
</li>
|
||
<li class="nav-group-task">
|
||
<a class="nav-group-task-link" href="Structs/SwiftLogNoOpLogHandler.html">SwiftLogNoOpLogHandler</a>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</nav>
|
||
<article class="main-content">
|
||
|
||
<section class="section">
|
||
<div class="section-content top-matter">
|
||
<h1>Structures</h1>
|
||
<p>The following structures are available globally.</p>
|
||
|
||
</div>
|
||
</section>
|
||
|
||
<section class="section">
|
||
<div class="section-content">
|
||
<div class="task-group">
|
||
<ul class="item-container">
|
||
<li class="item">
|
||
<div>
|
||
<code>
|
||
<a name="/s:7Logging6LoggerV"></a>
|
||
<a name="//apple_ref/swift/Struct/Logger" class="dashAnchor"></a>
|
||
<a class="token" href="#/s:7Logging6LoggerV">Logger</a>
|
||
</code>
|
||
</div>
|
||
<div class="height-container">
|
||
<div class="pointer-container"></div>
|
||
<section class="section">
|
||
<div class="pointer"></div>
|
||
<div class="abstract">
|
||
<p>A <code>Logger</code> is the central type in <code>SwiftLog</code>. Its central function is to emit log messages using one of the methods
|
||
corresponding to a log level.</p>
|
||
|
||
<p><code>Logger</code>s are value types with respect to the <code>logLevel</code> and the <code>metadata</code> (as well as the immutable <code>label</code>
|
||
and the selected <code><a href="Protocols/LogHandler.html">LogHandler</a></code>). Therefore, <code>Logger</code>s are suitable to be passed around between libraries if you want
|
||
to preserve metadata across libraries.</p>
|
||
|
||
<p>The most basic usage of a <code>Logger</code> is</p>
|
||
<pre class="highlight swift"><code><span class="n">logger</span><span class="o">.</span><span class="nf">info</span><span class="p">(</span><span class="s">"Hello World!"</span><span class="p">)</span>
|
||
</code></pre>
|
||
|
||
<a href="Structs/Logger.html" class="slightly-smaller">See more</a>
|
||
</div>
|
||
<div class="declaration">
|
||
<h4>Declaration</h4>
|
||
<div class="language">
|
||
<p class="aside-title">Swift</p>
|
||
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">Logger</span></code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="slightly-smaller">
|
||
<a href="https://github.com/apple/swift-log/tree/1.4.2/Sources/Logging/Logging.swift#L38-L49">Show on GitHub</a>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
</li>
|
||
<li class="item">
|
||
<div>
|
||
<code>
|
||
<a name="/s:7Logging19MultiplexLogHandlerV"></a>
|
||
<a name="//apple_ref/swift/Struct/MultiplexLogHandler" class="dashAnchor"></a>
|
||
<a class="token" href="#/s:7Logging19MultiplexLogHandlerV">MultiplexLogHandler</a>
|
||
</code>
|
||
</div>
|
||
<div class="height-container">
|
||
<div class="pointer-container"></div>
|
||
<section class="section">
|
||
<div class="pointer"></div>
|
||
<div class="abstract">
|
||
<p>A pseudo-<code><a href="Protocols/LogHandler.html">LogHandler</a></code> that can be used to send messages to multiple other <code><a href="Protocols/LogHandler.html">LogHandler</a></code>s.</p>
|
||
<h3 id='effective-logger-level' class='heading'>Effective Logger.Level</h3>
|
||
|
||
<p>When first initialized the multiplex log handlers’ log level is automatically set to the minimum of all the
|
||
passed in log handlers. This ensures that each of the handlers will be able to log at their appropriate level
|
||
any log events they might be interested in.</p>
|
||
|
||
<p>Example:
|
||
If log handler <code>A</code> is logging at <code>.debug</code> level, and log handler <code>B</code> is logging at <code>.info</code> level, the constructed
|
||
<code>MultiplexLogHandler([A, B])</code>‘s effective log level will be set to <code>.debug</code>, meaning that debug messages will be
|
||
handled by this handler, while only logged by the underlying <code>A</code> log handler (since <code>B</code>’s log level is <code>.info</code>
|
||
and thus it would not actually log that log message).</p>
|
||
|
||
<p>If the log level is <em>set</em> on a <code><a href="Structs/Logger.html">Logger</a></code> backed by an <code>MultiplexLogHandler</code> the log level will apply to <em>all</em>
|
||
underlying log handlers, allowing a logger to still select at what level it wants to log regardless of if the underlying
|
||
handler is a multiplex or a normal one. If for some reason one might want to not allow changing a log level of a specific
|
||
handler passed into the multiplex log handler, this is possible by wrapping it in a handler which ignores any log level changes.</p>
|
||
<h3 id='effective-logger-metadata' class='heading'>Effective Logger.Metadata</h3>
|
||
|
||
<p>Since a <code>MultiplexLogHandler</code> is a combination of multiple log handlers, the handling of metadata can be non-obvious.
|
||
For example, the underlying log handlers may have metadata of their own set before they are used to initialize the multiplex log handler.</p>
|
||
|
||
<p>The multiplex log handler acts purely as proxy and does not make any changes to underlying handler metadata other than
|
||
proxying writes that users made on a <code><a href="Structs/Logger.html">Logger</a></code> instance backed by this handler.</p>
|
||
|
||
<p>Setting metadata is always proxied through to <em>all</em> underlying handlers, meaning that if a modification like
|
||
<code>logger[metadataKey: "x"] = "y"</code> is made, all underlying log handlers that this multiplex handler was initiated with
|
||
will observe this change.</p>
|
||
|
||
<p>Reading metadata from the multiplex log handler MAY need to pick one of conflicting values if the underlying log handlers
|
||
were already initiated with some metadata before passing them into the multiplex handler. The multiplex handler uses
|
||
the order in which the handlers were passed in during its initialization as a priority indicator - the first handler’s
|
||
values are more important than the next handlers values, etc.</p>
|
||
|
||
<p>Example:
|
||
If the multiplex log handler was initiated with two handlers like this: <code>MultiplexLogHandler([handler1, handler2])</code>.
|
||
The handlers each have some already set metadata: <code>handler1</code> has metadata values for keys <code>one</code> and <code>all</code>, and <code>handler2</code>
|
||
has values for keys <code>two</code> and <code>all</code>.</p>
|
||
|
||
<p>A query through the multiplex log handler the key <code>one</code> naturally returns <code>handler1</code>’s value, and a query for <code>two</code>
|
||
naturally returns <code>handler2</code>’s value. Querying for the key <code>all</code> will return <code>handler1</code>’s value, as that handler was indicated
|
||
“more important” than the second handler. The same rule applies when querying for the <code>metadata</code> property of the
|
||
multiplex log handler - it constructs <code>Metadata</code> uniquing values.</p>
|
||
|
||
<a href="Structs/MultiplexLogHandler.html" class="slightly-smaller">See more</a>
|
||
</div>
|
||
<div class="declaration">
|
||
<h4>Declaration</h4>
|
||
<div class="language">
|
||
<p class="aside-title">Swift</p>
|
||
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">MultiplexLogHandler</span> <span class="p">:</span> <span class="kt"><a href="Protocols/LogHandler.html">LogHandler</a></span></code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="slightly-smaller">
|
||
<a href="https://github.com/apple/swift-log/tree/1.4.2/Sources/Logging/Logging.swift#L920-L991">Show on GitHub</a>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
</li>
|
||
<li class="item">
|
||
<div>
|
||
<code>
|
||
<a name="/s:7Logging16StreamLogHandlerV"></a>
|
||
<a name="//apple_ref/swift/Struct/StreamLogHandler" class="dashAnchor"></a>
|
||
<a class="token" href="#/s:7Logging16StreamLogHandlerV">StreamLogHandler</a>
|
||
</code>
|
||
</div>
|
||
<div class="height-container">
|
||
<div class="pointer-container"></div>
|
||
<section class="section">
|
||
<div class="pointer"></div>
|
||
<div class="abstract">
|
||
<p><code>StreamLogHandler</code> is a simple implementation of <code><a href="Protocols/LogHandler.html">LogHandler</a></code> for directing
|
||
<code><a href="Structs/Logger.html">Logger</a></code> output to either <code>stderr</code> or <code>stdout</code> via the factory methods.</p>
|
||
|
||
<a href="Structs/StreamLogHandler.html" class="slightly-smaller">See more</a>
|
||
</div>
|
||
<div class="declaration">
|
||
<h4>Declaration</h4>
|
||
<div class="language">
|
||
<p class="aside-title">Swift</p>
|
||
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">StreamLogHandler</span> <span class="p">:</span> <span class="kt"><a href="Protocols/LogHandler.html">LogHandler</a></span></code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="slightly-smaller">
|
||
<a href="https://github.com/apple/swift-log/tree/1.4.2/Sources/Logging/Logging.swift#L1076-L1156">Show on GitHub</a>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
</li>
|
||
<li class="item">
|
||
<div>
|
||
<code>
|
||
<a name="/s:7Logging012SwiftLogNoOpC7HandlerV"></a>
|
||
<a name="//apple_ref/swift/Struct/SwiftLogNoOpLogHandler" class="dashAnchor"></a>
|
||
<a class="token" href="#/s:7Logging012SwiftLogNoOpC7HandlerV">SwiftLogNoOpLogHandler</a>
|
||
</code>
|
||
</div>
|
||
<div class="height-container">
|
||
<div class="pointer-container"></div>
|
||
<section class="section">
|
||
<div class="pointer"></div>
|
||
<div class="abstract">
|
||
<p>No operation LogHandler, used when no logging is required</p>
|
||
|
||
<a href="Structs/SwiftLogNoOpLogHandler.html" class="slightly-smaller">See more</a>
|
||
</div>
|
||
<div class="declaration">
|
||
<h4>Declaration</h4>
|
||
<div class="language">
|
||
<p class="aside-title">Swift</p>
|
||
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">SwiftLogNoOpLogHandler</span> <span class="p">:</span> <span class="kt"><a href="Protocols/LogHandler.html">LogHandler</a></span></code></pre>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="slightly-smaller">
|
||
<a href="https://github.com/apple/swift-log/tree/1.4.2/Sources/Logging/Logging.swift#L1159-L1186">Show on GitHub</a>
|
||
</div>
|
||
</section>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
</article>
|
||
</div>
|
||
<section class="footer">
|
||
<p>© 2021 <a class="link" href="https://github.com/apple/swift-log" target="_blank" rel="external noopener">SwiftLog team</a>. All rights reserved. (Last updated: 2021-12-17)</p>
|
||
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
|
||
</section>
|
||
</body>
|
||
</html>
|