Skip to content

Commit ce1a89c

Browse files
authored
Merge pull request #2 from mitchtreece/dev
1.2.0 Release
2 parents 8348151 + f405c81 commit ce1a89c

File tree

4 files changed

+103
-20
lines changed

4 files changed

+103
-20
lines changed

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Mitch Treece
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Sources/Lumberjack/Logger/Logger.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ public class Logger: Equatable {
8888
let defaultComponents = Lumberjack.defaultLogger.configuration.components
8989
let components = Lumberjack.forceDefaultComponents ? defaultComponents : self.configuration.components
9090
let category = category ?? self.configuration.category
91-
let module = file.components(separatedBy: "/").first ?? "???"
92-
let fileWithExtension = file.components(separatedBy: "/").last ?? "???"
9391

9492
var _message = Message(
9593
message,
@@ -98,9 +96,8 @@ public class Logger: Equatable {
9896
level: level,
9997
symbol: symbol ?? self.configuration.symbol.asString(for: level),
10098
category: category,
101-
module: module,
102-
fileWithExtension: fileWithExtension,
103-
functionWithParameters: function,
99+
file: file,
100+
function: function,
104101
line: line,
105102
date: Date(),
106103
dateFormatter: self.configuration.dateFormatter
@@ -149,6 +146,27 @@ public class Logger: Equatable {
149146

150147
}
151148

149+
/// Proxy-logs a message produced by another logger.
150+
///
151+
/// - Parameters:
152+
/// - message: The message to log.
153+
///
154+
/// - Returns: The logged message.
155+
@discardableResult
156+
public func proxy(_ message: Message) -> Message {
157+
158+
return log(
159+
message.body(formatted: false),
160+
level: message.level,
161+
symbol: message.symbol,
162+
category: message.category,
163+
file: message.file,
164+
function: message.function,
165+
line: message.line
166+
)
167+
168+
}
169+
152170
/// Logs a debug message.
153171
///
154172
/// - Parameters:

Sources/Lumberjack/Lumberjack.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,37 @@ public func LOG(_ message: String,
284284

285285
}
286286

287+
/// Proxy-logs a message produced by another logger.
288+
///
289+
/// - Parameters:
290+
/// - message: The message to log.
291+
/// - target: The target to send the message to.
292+
///
293+
/// - Returns: The logged message, or `nil` if the target is invalid.
294+
@discardableResult
295+
public func PROXY(_ message: Message,
296+
target: LogTarget = .default) -> Message? {
297+
298+
var logger: Logger?
299+
300+
switch target {
301+
case .default:
302+
303+
logger = Lumberjack
304+
.defaultLogger
305+
306+
case .id(let id):
307+
308+
logger = Lumberjack
309+
.logger(id: id)
310+
311+
}
312+
313+
return logger?
314+
.proxy(message)
315+
316+
}
317+
287318
/// Logs a debug message.
288319
///
289320
/// - Parameters:

Sources/Lumberjack/Message/Message.swift

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,21 @@ public struct Message {
5454
/// The message's category.
5555
public let category: String?
5656

57-
/// The message's module.
58-
public let module: String
59-
6057
/// The message's line number.
6158
public let line: UInt
6259

6360
/// The message's date.
6461
public let date: Date
6562

63+
/// The message's module.
64+
public var module: String {
65+
66+
return self.file
67+
.components(separatedBy: "/")
68+
.first ?? "???"
69+
70+
}
71+
6672
/// The message's date as a formatted string.
6773
public var dateString: String {
6874

@@ -105,22 +111,30 @@ public struct Message {
105111
return "\(route)\(status)"
106112

107113
}
108-
114+
109115
private let body: String
110-
private let fileWithExtension: String
111-
private let functionWithParameters: String
116+
internal let file: String
117+
internal let function: String
118+
119+
private var fileWithExtension: String {
120+
121+
return self.file
122+
.components(separatedBy: "/")
123+
.last ?? "???"
124+
125+
}
126+
112127
private let dateFormatter: DateFormatter
113128
private var hooks = [HookEntry]()
114-
129+
115130
internal init(_ body: String,
116131
loggerId: String,
117132
components: [Component],
118133
level: LogLevel,
119134
symbol: String,
120135
category: String?,
121-
module: String,
122-
fileWithExtension: String,
123-
functionWithParameters: String,
136+
file: String,
137+
function: String,
124138
line: UInt,
125139
date: Date,
126140
dateFormatter: DateFormatter) {
@@ -133,9 +147,8 @@ public struct Message {
133147
self.symbol = symbol
134148
self.category = category
135149

136-
self.module = module
137-
self.fileWithExtension = fileWithExtension
138-
self.functionWithParameters = functionWithParameters
150+
self.file = file
151+
self.function = function
139152
self.line = line
140153

141154
self.date = date
@@ -173,13 +186,13 @@ public struct Message {
173186

174187
guard parameters else {
175188

176-
return self.functionWithParameters
189+
return self.function
177190
.components(separatedBy: "(")
178191
.first ?? "???"
179192

180193
}
181194

182-
return self.functionWithParameters
195+
return self.function
183196

184197
}
185198

0 commit comments

Comments
 (0)