Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
9b149a6a
Commit
9b149a6a
authored
Apr 21, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Logger: split longer messages into multiple.
parent
0edd3bff
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
1 deletions
+17
-1
1Weather/Common/Logger.swift
+17
-1
No files found.
1Weather/Common/Logger.swift
View file @
9b149a6a
...
...
@@ -25,9 +25,25 @@ final class Logger {
self
.
componentName
=
componentName
}
private
let
maxCharsPerMessage
=
900
// The Apple limit for NSLog is 1024. Leaving some space for timestamp, etc. Not sure if they are a part of 1024, but I think they are. Also, account for our own prefix (roughly)
func
log
(
level
:
LogLevel
,
message
:
String
)
{
#if DEBUG
NSLog
(
"
\(
Logger
.
prefix
)
\(
componentName
)
[
\(
logLevelString
(
level
:
level
)
)
]:
\(
message
)
"
)
let
prefix
=
"
\(
Logger
.
prefix
)
\(
componentName
)
[
\(
logLevelString
(
level
:
level
)
)
]"
if
message
.
count
<
maxCharsPerMessage
{
NSLog
(
"
\(
prefix
)
:
\(
message
)
"
)
}
else
{
var
partNumber
=
1
let
totalPartsCount
=
1
+
message
.
count
/
maxCharsPerMessage
var
remainingMessage
=
message
while
!
remainingMessage
.
isEmpty
{
let
messageToPrint
=
remainingMessage
.
prefix
(
maxCharsPerMessage
)
remainingMessage
=
String
(
remainingMessage
.
suffix
(
from
:
messageToPrint
.
endIndex
))
NSLog
(
"
\(
prefix
)
(part
\(
partNumber
)
/
\(
totalPartsCount
)
):
\(
messageToPrint
)
"
)
partNumber
+=
1
}
}
#endif
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment