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
b1d774af
Commit
b1d774af
authored
Apr 24, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added verbose logging (turned off by default). TODO: control via settings.
parent
4e2fac11
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
1Weather/Common/Logger.swift
+15
-2
1Weather/Model/LocationManager.swift
+3
-3
No files found.
1Weather/Common/Logger.swift
View file @
b1d774af
...
...
@@ -10,7 +10,10 @@ import Foundation
final
class
Logger
{
enum
LogLevel
{
public
var
minLogLevel
:
LogLevel
public
enum
LogLevel
:
Int
{
case
verbose
=
0
case
debug
case
info
case
warning
...
...
@@ -21,14 +24,18 @@ final class Logger {
var
componentName
:
String
init
(
componentName
:
String
)
{
init
(
componentName
:
String
,
minLogLevel
:
LogLevel
=
.
debug
)
{
self
.
componentName
=
componentName
self
.
minLogLevel
=
minLogLevel
}
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
guard
level
.
rawValue
>=
minLogLevel
.
rawValue
else
{
return
}
let
prefix
=
"
\(
Logger
.
prefix
)
\(
componentName
)
[
\(
logLevelString
(
level
:
level
)
)
]"
if
message
.
count
<
maxCharsPerMessage
{
NSLog
(
"
\(
prefix
)
:
\(
message
)
"
)
...
...
@@ -47,6 +54,10 @@ final class Logger {
#endif
}
func
verbose
(
_
message
:
String
)
{
log
(
level
:
.
verbose
,
message
:
message
)
}
func
debug
(
_
message
:
String
)
{
log
(
level
:
.
debug
,
message
:
message
)
}
...
...
@@ -65,6 +76,8 @@ final class Logger {
private
func
logLevelString
(
level
:
LogLevel
)
->
String
{
switch
level
{
case
.
verbose
:
return
"VERBOSE"
case
.
debug
:
return
"DEBUG"
case
.
info
:
...
...
1Weather/Model/LocationManager.swift
View file @
b1d774af
...
...
@@ -209,7 +209,7 @@ public class LocationManager {
public
func
updateHealth
(
for
location
:
Location
)
{
if
let
lastTimeUpdated
=
location
.
health
?
.
lastUpdateTime
{
guard
Date
()
.
timeIntervalSince
(
lastTimeUpdated
)
>=
healthSource
.
healthUpdateInterval
else
{
log
.
info
(
"Update health (
\(
location
)
): fresh enough (last updated at
\(
lastTimeUpdated
)
), skip update."
)
log
.
verbose
(
"Update health (
\(
location
)
): fresh enough (last updated at
\(
lastTimeUpdated
)
), skip update."
)
return
}
}
...
...
@@ -243,7 +243,7 @@ public class LocationManager {
public
func
updateNotifications
(
for
location
:
Location
)
{
if
let
lastTimeUpdated
=
location
.
notifications
?
.
updatedAt
{
guard
Date
()
.
timeIntervalSince
(
lastTimeUpdated
)
>=
nwsAlertsManager
.
updateInterval
else
{
log
.
info
(
"Update notifications (
\(
location
)
): fresh enough (last updated at
\(
lastTimeUpdated
)
, skip update"
)
log
.
verbose
(
"Update notifications (
\(
location
)
): fresh enough (last updated at
\(
lastTimeUpdated
)
, skip update"
)
return
}
}
...
...
@@ -279,7 +279,7 @@ public class LocationManager {
}
if
let
lastTimeUpdated
=
location
.
lastWeatherUpdateDate
{
guard
Date
()
.
timeIntervalSince
(
lastTimeUpdated
)
>=
weatherUpdateSource
.
weatherUpdateInterval
else
{
log
.
info
(
"Update weather (
\(
location
)
): fresh enough (last updated at
\(
lastTimeUpdated
)
), skip update."
)
log
.
verbose
(
"Update weather (
\(
location
)
): fresh enough (last updated at
\(
lastTimeUpdated
)
), skip update."
)
return
}
}
...
...
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