Skip to content

Commit

Permalink
add OSLoggerAppender
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Aug 10, 2022
1 parent 0dc0e2e commit 3dfda58
Show file tree
Hide file tree
Showing 36 changed files with 673 additions and 56 deletions.
Binary file modified .DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions Logboard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
29617B13232E6DEA00AD06AE /* SocketAppender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29617AF5232E6D7D00AD06AE /* SocketAppender.swift */; };
29617B14232E6DEB00AD06AE /* SocketAppender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29617AF5232E6D7D00AD06AE /* SocketAppender.swift */; };
29617B15232E6DEC00AD06AE /* SocketAppender.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29617AF5232E6D7D00AD06AE /* SocketAppender.swift */; };
BCA00718289EAFF200AAA74D /* OSLoggerAppender.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCA00717289EAFF200AAA74D /* OSLoggerAppender.swift */; };
BCA00719289EAFF200AAA74D /* OSLoggerAppender.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCA00717289EAFF200AAA74D /* OSLoggerAppender.swift */; };
BCA0071A289EAFF200AAA74D /* OSLoggerAppender.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCA00717289EAFF200AAA74D /* OSLoggerAppender.swift */; };
BCA0071B289EAFF200AAA74D /* OSLoggerAppender.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCA00717289EAFF200AAA74D /* OSLoggerAppender.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -64,6 +68,7 @@
29617AF7232E6D7D00AD06AE /* MultiAppender.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MultiAppender.swift; path = Sources/Logboard/MultiAppender.swift; sourceTree = "<group>"; };
29617AF8232E6D7D00AD06AE /* Logboard.Data.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Logboard.Data.swift; path = Sources/Logboard/Logboard.Data.swift; sourceTree = "<group>"; };
29617B16232E6E7900AD06AE /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
BCA00717289EAFF200AAA74D /* OSLoggerAppender.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLoggerAppender.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -194,6 +199,7 @@
29617AF7232E6D7D00AD06AE /* MultiAppender.swift */,
29617AF3232E6D7D00AD06AE /* NullAppender.swift */,
29617AF5232E6D7D00AD06AE /* SocketAppender.swift */,
BCA00717289EAFF200AAA74D /* OSLoggerAppender.swift */,
);
name = Logboard;
sourceTree = "<group>";
Expand Down Expand Up @@ -399,6 +405,7 @@
files = (
29617AFF232E6D7D00AD06AE /* Logboard.Data.swift in Sources */,
29617AF9232E6D7D00AD06AE /* LogboardAppender.swift in Sources */,
BCA00718289EAFF200AAA74D /* OSLoggerAppender.swift in Sources */,
29617AFA232E6D7D00AD06AE /* NullAppender.swift in Sources */,
29617AFE232E6D7D00AD06AE /* MultiAppender.swift in Sources */,
29617AFB232E6D7D00AD06AE /* Logboard.swift in Sources */,
Expand All @@ -413,6 +420,7 @@
files = (
29617B04232E6DD300AD06AE /* Logboard.Data.swift in Sources */,
29617B01232E6DB600AD06AE /* ConsoleAppender.swift in Sources */,
BCA00719289EAFF200AAA74D /* OSLoggerAppender.swift in Sources */,
29617B0D232E6DE100AD06AE /* MultiAppender.swift in Sources */,
29617B0A232E6DDC00AD06AE /* LogboardAppender.swift in Sources */,
29617B13232E6DEA00AD06AE /* SocketAppender.swift in Sources */,
Expand All @@ -427,6 +435,7 @@
files = (
29617B05232E6DD400AD06AE /* Logboard.Data.swift in Sources */,
29617B02232E6DB700AD06AE /* ConsoleAppender.swift in Sources */,
BCA0071A289EAFF200AAA74D /* OSLoggerAppender.swift in Sources */,
29617B0E232E6DE100AD06AE /* MultiAppender.swift in Sources */,
29617B0B232E6DDD00AD06AE /* LogboardAppender.swift in Sources */,
29617B14232E6DEB00AD06AE /* SocketAppender.swift in Sources */,
Expand All @@ -441,6 +450,7 @@
files = (
29617B06232E6DD500AD06AE /* Logboard.Data.swift in Sources */,
29617B03232E6DB700AD06AE /* ConsoleAppender.swift in Sources */,
BCA0071B289EAFF200AAA74D /* OSLoggerAppender.swift in Sources */,
29617B0F232E6DE200AD06AE /* MultiAppender.swift in Sources */,
29617B0C232E6DDD00AD06AE /* LogboardAppender.swift in Sources */,
29617B15232E6DEC00AD06AE /* SocketAppender.swift in Sources */,
Expand Down
60 changes: 60 additions & 0 deletions OSLoggerAppender.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Foundation

#if canImport(OSLog)
import OSLog
#endif

/// The OSLoggerAppender class can output your Console.app with os_log function.
/// - seealso: https://developer.apple.com/documentation/os/logging/generating_log_messages_from_your_code
@available(iOS 14.0, *)
@available(macOS 11.0, *)
@available(tvOS 14.0, *)
@available(watchOS 7.0, *)
public class OSLoggerAppender: LogboardAppender {
private let logger: Logger

/// Creates a logger using the specified subsystem and category.
public init(sybsystem: String, category: String) {
logger = Logger(subsystem: sybsystem, category: category)
}

public func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
let message =
"[\(filename(file.description)):\(line)]" +
function.description +
">" +
message.map({ String(describing: $0) }).joined(separator: "")
switch level {
case .trace:
logger.trace("\(message)")
case .debug:
logger.debug("\(message)")
case .info:
logger.info("\(message)")
case .warn:
logger.warning("\(message)")
case .error:
logger.error("\(message)")
}
}

public func append(_ logboard: Logboard, level: Logboard.Level, format: String, arguments: CVarArg, file: StaticString, function: StaticString, line: Int) {
let message =
"[\(filename(file.description)):\(line)]" +
function.description +
">" +
String(format: format, arguments)
switch level {
case .trace:
logger.trace("\(message)")
case .debug:
logger.debug("\(message)")
case .info:
logger.info("\(message)")
case .warn:
logger.warning("\(message)")
case .error:
logger.error("\(message)")
}
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[![CocoaPods](https://img.shields.io/cocoapods/v/Logboard.svg?style=flat)](http://cocoapods.org/pods/Logboard)
[![GitHub license](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/shogo4405/Logboard/blob/master/LICENSE.md)

Simple logging framework for your framework project.
* Simple logging framework for your framework project.
* [API Documentation](https://shogo4405.github.io/Logboard/)

## Usage
```swift
Expand Down
2 changes: 1 addition & 1 deletion Sources/Logboard/Logboard.Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension Logboard {
}

extension Logboard.Data: CustomStringConvertible {
/// MARK: CustomStringConvertible
// MARK: CustomStringConvertible
public var description: String {
return "\(Logboard.dateFormatter.string(from: date)) [\(level)] [\(identifier)] [\(filename(file)):\(line)] \(function) > \(message)"
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Logboard/MultiAppender.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

/// The MultiAppender class delegate appenders.
/// The MultiAppender class delegates appenders.
/// ## Example code:
/// ```
/// let multi = MultiAppender()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Logboard/NullAppender.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

/// The NullAppender class do output no message.
/// The NullAppender class does output no message.
public class NullAppender: LogboardAppender {
public func append(_ logboard: Logboard, level: Logboard.Level, message: [Any], file: StaticString, function: StaticString, line: Int) {
}
Expand Down
43 changes: 40 additions & 3 deletions docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<li class="nav-group-task">
<a href="Classes/NullAppender.html">NullAppender</a>
</li>
<li class="nav-group-task">
<a href="Classes/OSLoggerAppender.html">OSLoggerAppender</a>
</li>
<li class="nav-group-task">
<a href="Classes/SocketAppender.html">SocketAppender</a>
</li>
Expand All @@ -81,6 +84,40 @@ <h1>Classes</h1>
<section class="section task-group-section">
<div class="task-group">
<ul>
<li class="item">
<div>
<code>
<a name="/s:8Logboard16OSLoggerAppenderC"></a>
<a name="//apple_ref/swift/Class/OSLoggerAppender" class="dashAnchor"></a>
<a class="token" href="#/s:8Logboard16OSLoggerAppenderC">OSLoggerAppender</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The OSLoggerAppender class can output your Console.app with os_log function.</p>
<div class="aside aside-seealso">
<p class="aside-title">Seealso</p>
<a href="https://developer.apple.com/documentation/os/logging/generating_log_messages_from_your_code">https://developer.apple.com/documentation/os/logging/generating_log_messages_from_your_code</a>

</div>

<a href="Classes/OSLoggerAppender.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">@available</span><span class="p">(</span><span class="n">iOS</span> <span class="mf">14.0</span><span class="p">,</span> <span class="n">macOS</span> <span class="mf">11.0</span><span class="p">,</span> <span class="n">tvOS</span> <span class="mf">14.0</span><span class="p">,</span> <span class="n">watchOS</span> <span class="mf">7.0</span><span class="p">,</span> <span class="o">*</span><span class="p">)</span>
<span class="kd">public</span> <span class="kd">class</span> <span class="kt">OSLoggerAppender</span> <span class="p">:</span> <span class="kt"><a href="Protocols/LogboardAppender.html">LogboardAppender</a></span></code></pre>

</div>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
Expand Down Expand Up @@ -150,7 +187,7 @@ <h4>Declaration</h4>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The MultiAppender class delegate appenders.</p>
<p>The MultiAppender class delegates appenders.</p>
<h2 id='example-code' class='heading'>Example code:</h2>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">multi</span> <span class="o">=</span> <span class="kt">MultiAppender</span><span class="p">()</span>
<span class="n">multi</span><span class="o">.</span><span class="n">appenders</span><span class="o">.</span><span class="nf">append</span><span class="p">(</span><span class="kt">ConsoleAppender</span><span class="p">())</span>
Expand Down Expand Up @@ -184,7 +221,7 @@ <h4>Declaration</h4>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>The NullAppender class do output no message.</p>
<p>The NullAppender class does output no message.</p>

<a href="Classes/NullAppender.html" class="slightly-smaller">See more</a>
</div>
Expand Down Expand Up @@ -232,7 +269,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-06)</p>
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-07)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
5 changes: 4 additions & 1 deletion docs/Classes/ConsoleAppender.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<li class="nav-group-task">
<a href="../Classes/NullAppender.html">NullAppender</a>
</li>
<li class="nav-group-task">
<a href="../Classes/OSLoggerAppender.html">OSLoggerAppender</a>
</li>
<li class="nav-group-task">
<a href="../Classes/SocketAppender.html">SocketAppender</a>
</li>
Expand Down Expand Up @@ -145,7 +148,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-06)</p>
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-07)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
5 changes: 4 additions & 1 deletion docs/Classes/Logboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<li class="nav-group-task">
<a href="../Classes/NullAppender.html">NullAppender</a>
</li>
<li class="nav-group-task">
<a href="../Classes/OSLoggerAppender.html">OSLoggerAppender</a>
</li>
<li class="nav-group-task">
<a href="../Classes/SocketAppender.html">SocketAppender</a>
</li>
Expand Down Expand Up @@ -609,7 +612,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-06)</p>
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-07)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
25 changes: 20 additions & 5 deletions docs/Classes/Logboard/Data.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<li class="nav-group-task">
<a href="../../Classes/NullAppender.html">NullAppender</a>
</li>
<li class="nav-group-task">
<a href="../../Classes/OSLoggerAppender.html">OSLoggerAppender</a>
</li>
<li class="nav-group-task">
<a href="../../Classes/SocketAppender.html">SocketAppender</a>
</li>
Expand Down Expand Up @@ -305,21 +308,33 @@ <h4>Declaration</h4>
</section>
</div>
</li>
</ul>
</div>
<div class="task-group">
<div class="task-name-container">
<a name="/CustomStringConvertible"></a>
<a name="//apple_ref/swift/Section/CustomStringConvertible" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/CustomStringConvertible"></a>
<h3 class="section-name"><span>CustomStringConvertible</span>
</h3>
</div>
</div>
<ul>
<li class="item">
<div>
<code>
<a name="/s:8LogboardAAC4DataV11descriptionSSvp"></a>
<a name="/s:s23CustomStringConvertibleP11descriptionSSvp"></a>
<a name="//apple_ref/swift/Property/description" class="dashAnchor"></a>
<a class="token" href="#/s:8LogboardAAC4DataV11descriptionSSvp">description</a>
<a class="token" href="#/s:s23CustomStringConvertibleP11descriptionSSvp">description</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>MARK: CustomStringConvertible</p>


</div>
<div class="declaration">
<h4>Declaration</h4>
Expand All @@ -337,7 +352,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-06)</p>
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-07)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
5 changes: 4 additions & 1 deletion docs/Classes/Logboard/Level.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<li class="nav-group-task">
<a href="../../Classes/NullAppender.html">NullAppender</a>
</li>
<li class="nav-group-task">
<a href="../../Classes/OSLoggerAppender.html">OSLoggerAppender</a>
</li>
<li class="nav-group-task">
<a href="../../Classes/SocketAppender.html">SocketAppender</a>
</li>
Expand Down Expand Up @@ -282,7 +285,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-06)</p>
<p>&copy; 2022 <a class="link" href="https://github.com/shogo4405/Logboard" target="_blank" rel="external noopener">shogo4405</a>. All rights reserved. (Last updated: 2022-08-07)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading

0 comments on commit 3dfda58

Please sign in to comment.