You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/SimpleLogging/LogChannel/LogChannel.swift
+30-74Lines changed: 30 additions & 74 deletions
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,16 @@ public struct LogChannel<Location: UnreliableLogChannelLocation>: AnyLogChannel
40
40
publicvarseverityFilter:LogSeverityFilter
41
41
42
42
/// The style of the severity part of a log line in this channel
43
-
publicletlogSeverityNameStyle:SeverityNameStyle
43
+
@inline(__always)
44
+
publicvarlogSeverityNameStyle:SeverityNameStyle{
45
+
get{ options.severityStyle }
46
+
47
+
@available(*, unavailable, message:"""
48
+
Ability to change a channel's log severity was removed in SimpleLogging 0.6 to reduce complexity and improve performance.
49
+
See PR #17: https://github.com/RougeWare/Swift-Simple-Logging/pull/17
50
+
""")
51
+
set{}
52
+
}
44
53
45
54
46
55
/// The logging options to use with each message
@@ -54,10 +63,8 @@ public struct LogChannel<Location: UnreliableLogChannelLocation>: AnyLogChannel
54
63
/// - Parameters:
55
64
/// - name: The human-readable name of the channel
56
65
/// - location: The location where the logs are channeled to
57
-
/// - severityFilter: _optional_ - The filter which decides which messages appear in this channel's logs. Defaults to allowing `info` and higher, since `info` is the lowest built-in severity which users might care about if they're looking at logs, but not debugging the code itself.
66
+
/// - severityFilter: _optional_ - The filter which decides which messages appear in this channel's logs. Defaults to `.default`
58
67
/// - logSeverityNameStyle: _optional_ - The style of the severity names that appear in the log. Defaults to `.default`.
59
-
///
60
-
/// - Throws: Any error which occurs while trying to create the channel
61
68
publicinit(
62
69
name:String,
63
70
location:Location,
@@ -67,7 +74,6 @@ public struct LogChannel<Location: UnreliableLogChannelLocation>: AnyLogChannel
@@ -79,8 +85,6 @@ public struct LogChannel<Location: UnreliableLogChannelLocation>: AnyLogChannel
79
85
/// - location: The location to which this channel sends its log messages
80
86
/// - lowestAllowedSeverity: _optional_ - The lowest severity which will appear in this channel's logs. Defaults to `defaultFilter`, since that's the lowest built-in severity which users might care about if they're looking at logs, but not debugging the code itself.
81
87
/// - logSeverityNameStyle: _optional_ - The style of the severity names that appear in the log. Defaults to `.default`.
82
-
///
83
-
/// - Throws: Any error which occurs while trying to create the channel
84
88
publicinit(
85
89
name:String,
86
90
location:Location,
@@ -97,12 +101,16 @@ public struct LogChannel<Location: UnreliableLogChannelLocation>: AnyLogChannel
97
101
98
102
99
103
104
+
// MARK: - Appending
105
+
100
106
publicextensionLogChannel{
101
107
102
-
/// Appends the given log message to this channel. If that can't be done, (for example, if the channel's location
103
-
/// is a file on a read-only volume) a semantic error is thrown.
108
+
/// Appends the given log message to this channel if the severity filter allows. If that can't be done, (for example, if the channel's location
109
+
/// is a file on a read-only volume) a description of the problem, along with the logged message,is printed to the destination of Swift's built-in ``print(_:)``.
104
110
///
105
-
/// - Note: The channel might choose to hold this log message in a buffer, for instance while it waits for a log file to be created
111
+
/// Of course, if the severity filter does not allow this message, then no action is taken.
112
+
///
113
+
/// - Note: The channel might choose to hold this log message in a buffer, for instance while it waits for a log file to be created, or a network call to complete.
106
114
///
107
115
/// - Parameter message: The message to append to this channel
108
116
func append(_ message:LogMessageProtocol){
@@ -121,74 +129,22 @@ public extension LogChannel {
121
129
""")
122
130
}
123
131
}
124
-
}
125
-
126
-
127
-
128
-
// MARK: - LogSeverityFilter
129
-
130
-
/// A filter which can be applied to a log channel to specify which messages are allowed through, based on their severities
131
-
//@dynamicMemberLookup // Would love this, but doesn't seem it works quite yet
132
-
publicenumLogSeverityFilter{
133
-
134
-
/// All messages are allowed
135
-
case allowAll
136
-
137
-
/// No messages are allowed
138
-
case allowNone
139
-
140
-
/// Only allow messages of this severity
141
-
case only(LogSeverity)
142
-
143
-
/// Only allow messages whose severity is in this range of severities
/// Whether or not this filter allows the given message to be logged
134
+
/// Appends the given log message to this channel if the severity filter allows.
165
135
///
166
-
/// - Parameter message: The message which might be allowed through this filter
167
-
/// - Returns: `true` iff the given message is allowed through this filter
168
-
@inline(__always)
169
-
func allows(_ message:LogMessageProtocol)->Bool{
170
-
allows(message.severity)
171
-
}
172
-
173
-
174
-
/// Whether or not this fitler allows messages with the given severity to be logged
136
+
/// Of course, if the severity filter does not allow this message, then no action is taken.
175
137
///
176
-
/// - Parameter severity: A severity to check against this filter
177
-
/// - Returns: `true` iff messages with the given severity are allowed through this filter
178
-
@inlinable
179
-
func allows(_ severity:LogSeverity)->Bool{
180
-
switchself{
181
-
case.allowAll:returntrue
182
-
case.allowNone:returnfalse
183
-
184
-
case.only(severity):returntrue
185
-
case.only(_):returnfalse
186
-
187
-
case.range(let range):
188
-
return range.contains(severity)
189
-
190
-
case.specificAndHigher(lowest:let lowest):
191
-
return lowest <= severity
138
+
/// - Note: The channel might choose to hold this log message in a buffer, for instance while it waits for a log file to be created, or a network call to complete.
139
+
///
140
+
/// - Parameter message: The message to append to this channel
0 commit comments