Skip to content

Commit

Permalink
Merge branch 'master' of github.com:emaloney/CleanroomLogger
Browse files Browse the repository at this point in the history
# Conflicts:
#	Documentation/API/docsets/CleanroomLogger.tgz
  • Loading branch information
Evan Maloney committed Jan 9, 2017
2 parents 9c18ba8 + 38d5dc2 commit a20956e
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 25 deletions.
82 changes: 76 additions & 6 deletions Documentation/API/Enums/OSLogTypeTranslator.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,69 @@ <h1>OSLogTypeTranslator</h1>

</section>
<section class="section task-group-section">
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_"></a>
<a name="//apple_ref/swift/Element/default" class="dashAnchor"></a>
<a class="token" href="#/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_">default</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The most direct translation from a <code><a href="../Structs/LogEntry.html">LogEntry</a></code>&rsquo;s <code>severity</code> to the
corresponding <code>OSLogType</code> value.</p>

<p>This value strikes a sensible balance between the higher-overhead logging
provided by <code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator6strictFMS0_S0_">.strict</a></code> and the more ephemeral logging of <code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator7relaxedFMS0_S0_">.relaxed</a></code>.</p>

<table><thead>
<tr>
<th>LogSeverity</th>
<th>OSLogType</th>
</tr>
</thead><tbody>
<tr>
<td><code>.verbose</code></td>
<td><code>.debug</code></td>
</tr>
<tr>
<td><code>.debug</code></td>
<td><code>.debug</code></td>
</tr>
<tr>
<td><code>.info</code></td>
<td><code>.info</code></td>
</tr>
<tr>
<td><code>.warning</code></td>
<td><code>.default</code></td>
</tr>
<tr>
<td><code>.error</code></td>
<td><code>.error</code></td>
</tr>
</tbody></table>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="k">case</span> <span class="err">`</span><span class="k">default</span><span class="err">`</span></code></pre>

</div>
</div>
</section>
</div>
</li>
</ul>
</div>
<div class="task-group">
<ul>
<li class="item">
Expand All @@ -242,7 +305,11 @@ <h1>OSLogTypeTranslator</h1>
<div class="pointer"></div>
<div class="abstract">
<p>A strict translation from a <code><a href="../Structs/LogEntry.html">LogEntry</a></code>&rsquo;s <code>severity</code> to an
<code>OSLogType</code> value. Warnings are treated as errors.</p>
<code>OSLogType</code> value. Warnings are treated as errors; errors are
treated as faults.</p>

<p>This will result in additional logging overhead being recorded by OSLog,
and is not recommended unless you have a specific need for this.</p>

<table><thead>
<tr>
Expand All @@ -260,7 +327,7 @@ <h1>OSLogTypeTranslator</h1>
</tr>
<tr>
<td><code>.info</code></td>
<td><code>.default</code></td>
<td><code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_">.default</a></code></td>
</tr>
<tr>
<td><code>.warning</code></td>
Expand Down Expand Up @@ -302,7 +369,10 @@ <h4>Declaration</h4>
<div class="pointer"></div>
<div class="abstract">
<p>A relaxed translation from a <code><a href="../Structs/LogEntry.html">LogEntry</a></code>&rsquo;s <code>severity</code> to an
<code>OSLogType</code> value. Warnings are treated as informational log messages.</p>
<code>OSLogType</code> value. Nothing is treated as an error.</p>

<p>This results in low-overhead logging, but log entries are more
ephemeral and may not contain as much OSLog metadata.</p>

<table><thead>
<tr>
Expand All @@ -320,15 +390,15 @@ <h4>Declaration</h4>
</tr>
<tr>
<td><code>.info</code></td>
<td><code>.default</code></td>
<td><code>.info</code></td>
</tr>
<tr>
<td><code>.warning</code></td>
<td><code>.default</code></td>
<td><code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_">.default</a></code></td>
</tr>
<tr>
<td><code>.error</code></td>
<td><code>.error</code></td>
<td><code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_">.default</a></code></td>
</tr>
</tbody></table>

Expand Down
2 changes: 1 addition & 1 deletion Documentation/API/Structs/OSLogRecorder.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ <h4>Declaration</h4>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">?(</span><span class="nv">formatters</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Protocols/LogFormatter.html">LogFormatter</a></span><span class="p">],</span> <span class="nv">subsystem</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">""</span><span class="p">,</span> <span class="nv">logTypeTranslator</span><span class="p">:</span> <span class="kt"><a href="../Enums/OSLogTypeTranslator.html">OSLogTypeTranslator</a></span> <span class="o">=</span> <span class="o">.</span><span class="n">strict</span><span class="p">,</span> <span class="nv">queue</span><span class="p">:</span> <span class="kt">DispatchQueue</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>
<pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">?(</span><span class="nv">formatters</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Protocols/LogFormatter.html">LogFormatter</a></span><span class="p">],</span> <span class="nv">subsystem</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">""</span><span class="p">,</span> <span class="nv">logTypeTranslator</span><span class="p">:</span> <span class="kt"><a href="../Enums/OSLogTypeTranslator.html">OSLogTypeTranslator</a></span> <span class="o">=</span> <span class="o">.</span><span class="k">default</span><span class="p">,</span> <span class="nv">queue</span><span class="p">:</span> <span class="kt">DispatchQueue</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>

</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,69 @@ <h1>OSLogTypeTranslator</h1>

</section>
<section class="section task-group-section">
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_"></a>
<a name="//apple_ref/swift/Element/default" class="dashAnchor"></a>
<a class="token" href="#/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_">default</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The most direct translation from a <code><a href="../Structs/LogEntry.html">LogEntry</a></code>&rsquo;s <code>severity</code> to the
corresponding <code>OSLogType</code> value.</p>

<p>This value strikes a sensible balance between the higher-overhead logging
provided by <code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator6strictFMS0_S0_">.strict</a></code> and the more ephemeral logging of <code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator7relaxedFMS0_S0_">.relaxed</a></code>.</p>

<table><thead>
<tr>
<th>LogSeverity</th>
<th>OSLogType</th>
</tr>
</thead><tbody>
<tr>
<td><code>.verbose</code></td>
<td><code>.debug</code></td>
</tr>
<tr>
<td><code>.debug</code></td>
<td><code>.debug</code></td>
</tr>
<tr>
<td><code>.info</code></td>
<td><code>.info</code></td>
</tr>
<tr>
<td><code>.warning</code></td>
<td><code>.default</code></td>
</tr>
<tr>
<td><code>.error</code></td>
<td><code>.error</code></td>
</tr>
</tbody></table>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="k">case</span> <span class="err">`</span><span class="k">default</span><span class="err">`</span></code></pre>

</div>
</div>
</section>
</div>
</li>
</ul>
</div>
<div class="task-group">
<ul>
<li class="item">
Expand All @@ -242,7 +305,11 @@ <h1>OSLogTypeTranslator</h1>
<div class="pointer"></div>
<div class="abstract">
<p>A strict translation from a <code><a href="../Structs/LogEntry.html">LogEntry</a></code>&rsquo;s <code>severity</code> to an
<code>OSLogType</code> value. Warnings are treated as errors.</p>
<code>OSLogType</code> value. Warnings are treated as errors; errors are
treated as faults.</p>

<p>This will result in additional logging overhead being recorded by OSLog,
and is not recommended unless you have a specific need for this.</p>

<table><thead>
<tr>
Expand All @@ -260,7 +327,7 @@ <h1>OSLogTypeTranslator</h1>
</tr>
<tr>
<td><code>.info</code></td>
<td><code>.default</code></td>
<td><code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_">.default</a></code></td>
</tr>
<tr>
<td><code>.warning</code></td>
Expand Down Expand Up @@ -302,7 +369,10 @@ <h4>Declaration</h4>
<div class="pointer"></div>
<div class="abstract">
<p>A relaxed translation from a <code><a href="../Structs/LogEntry.html">LogEntry</a></code>&rsquo;s <code>severity</code> to an
<code>OSLogType</code> value. Warnings are treated as informational log messages.</p>
<code>OSLogType</code> value. Nothing is treated as an error.</p>

<p>This results in low-overhead logging, but log entries are more
ephemeral and may not contain as much OSLog metadata.</p>

<table><thead>
<tr>
Expand All @@ -320,15 +390,15 @@ <h4>Declaration</h4>
</tr>
<tr>
<td><code>.info</code></td>
<td><code>.default</code></td>
<td><code>.info</code></td>
</tr>
<tr>
<td><code>.warning</code></td>
<td><code>.default</code></td>
<td><code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_">.default</a></code></td>
</tr>
<tr>
<td><code>.error</code></td>
<td><code>.error</code></td>
<td><code><a href="../Enums/OSLogTypeTranslator.html#/s:FO15CleanroomLogger19OSLogTypeTranslator7defaultFMS0_S0_">.default</a></code></td>
</tr>
</tbody></table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ <h4>Declaration</h4>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">?(</span><span class="nv">formatters</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Protocols/LogFormatter.html">LogFormatter</a></span><span class="p">],</span> <span class="nv">subsystem</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">""</span><span class="p">,</span> <span class="nv">logTypeTranslator</span><span class="p">:</span> <span class="kt"><a href="../Enums/OSLogTypeTranslator.html">OSLogTypeTranslator</a></span> <span class="o">=</span> <span class="o">.</span><span class="n">strict</span><span class="p">,</span> <span class="nv">queue</span><span class="p">:</span> <span class="kt">DispatchQueue</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>
<pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">?(</span><span class="nv">formatters</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Protocols/LogFormatter.html">LogFormatter</a></span><span class="p">],</span> <span class="nv">subsystem</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">""</span><span class="p">,</span> <span class="nv">logTypeTranslator</span><span class="p">:</span> <span class="kt"><a href="../Enums/OSLogTypeTranslator.html">OSLogTypeTranslator</a></span> <span class="o">=</span> <span class="o">.</span><span class="k">default</span><span class="p">,</span> <span class="nv">queue</span><span class="p">:</span> <span class="kt">DispatchQueue</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>

</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"warnings": [

],
"source_directory": "/Users/emaloney/Documents/Code/managed/CleanroomLogger"
"source_directory": "/Users/emaloney/Documents/Code/client/gilt-ios/Carthage/Checkouts/CleanroomLogger"
}
Binary file not shown.
2 changes: 1 addition & 1 deletion Sources/OSLogRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public struct OSLogRecorder: LogRecorder
- parameter queue: The `DispatchQueue` to use for the recorder. If `nil`,
a new queue will be created.
*/
public init?(formatters: [LogFormatter], subsystem: String = "", logTypeTranslator: OSLogTypeTranslator = .strict, queue: DispatchQueue? = nil)
public init?(formatters: [LogFormatter], subsystem: String = "", logTypeTranslator: OSLogTypeTranslator = .default, queue: DispatchQueue? = nil)
{
guard #available(iOS 10.0, macOS 10.12, tvOS 10.0, watchOS 3.0, *) else {
return nil
Expand Down
52 changes: 43 additions & 9 deletions Sources/OSLogTypeTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,29 @@ import os.log
*/
public enum OSLogTypeTranslator
{
/** The most direct translation from a `LogEntry`'s `severity` to the
corresponding `OSLogType` value.

This value strikes a sensible balance between the higher-overhead logging
provided by `.strict` and the more ephemeral logging of `.relaxed`.

LogSeverity|OSLogType
-----------|---------
`.verbose`|`.debug`
`.debug`|`.debug`
`.info`|`.info`
`.warning`|`.default`
`.error`|`.error`
*/
case `default`

/** A strict translation from a `LogEntry`'s `severity` to an
`OSLogType` value. Warnings are treated as errors.
`OSLogType` value. Warnings are treated as errors; errors are
treated as faults.

This will result in additional logging overhead being recorded by OSLog,
and is not recommended unless you have a specific need for this.

LogSeverity|OSLogType
-----------|---------
`.verbose`|`.debug`
Expand All @@ -36,21 +56,24 @@ public enum OSLogTypeTranslator
case strict

/** A relaxed translation from a `LogEntry`'s `severity` to an
`OSLogType` value. Warnings are treated as informational log messages.
`OSLogType` value. Nothing is treated as an error.

This results in low-overhead logging, but log entries are more
ephemeral and may not contain as much OSLog metadata.

LogSeverity|OSLogType
-----------|---------
`.verbose`|`.debug`
`.debug`|`.debug`
`.info`|`.default`
`.info`|`.info`
`.warning`|`.default`
`.error`|`.error`
`.error`|`.default`
*/
case relaxed

/** `OSLogType.default` is used for all messages. */
case allAsDefault

/** `OSLogType.info` is used for all messages. */
case allAsInfo

Expand All @@ -77,6 +100,17 @@ extension OSLogTypeTranslator
}

switch self {
case .default:
return { entry -> OSLogType in
switch entry.severity {
case .verbose: return .debug
case .debug: return .debug
case .info: return .info
case .warning: return .default
case .error: return .error
}
}

case .strict:
return { entry -> OSLogType in
switch entry.severity {
Expand All @@ -87,15 +121,15 @@ extension OSLogTypeTranslator
case .error: return .fault
}
}

case .relaxed:
return { entry -> OSLogType in
switch entry.severity {
case .verbose: return .debug
case .debug: return .debug
case .info: return .default
case .info: return .info
case .warning: return .default
case .error: return .error
case .error: return .default
}
}

Expand Down

0 comments on commit a20956e

Please sign in to comment.