Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gaba
fenix
Commits
a628f6f8
Unverified
Commit
a628f6f8
authored
Oct 13, 2020
by
Mihai Adrian Carare
Committed by
GitHub
Oct 13, 2020
Browse files
For #14735: Uplift - Remove debug logs from release build. (#15801)
parent
cae16cd2
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/proguard-rules.pro
View file @
a628f6f8
...
...
@@ -45,6 +45,14 @@
boolean
ANDROID_DETECTED
return
true
;
}
####################################################################################################
#
Remove
debug
logs
from
release
builds
####################################################################################################
-
assumenosideeffects
class
android
.
util
.
Log
{
public
static
boolean
isLoggable
(
java
.
lang
.
String
,
int
);
public
static
int
d
(...);
}
####################################################################################################
#
Mozilla
Application
Services
####################################################################################################
...
...
app/src/main/java/org/mozilla/fenix/FenixApplication.kt
View file @
a628f6f8
...
...
@@ -32,7 +32,6 @@ import mozilla.components.service.glean.config.Configuration
import
mozilla.components.service.glean.net.ConceptFetchHttpUploader
import
mozilla.components.support.base.log.Log
import
mozilla.components.support.base.log.logger.Logger
import
mozilla.components.support.base.log.sink.AndroidLogSink
import
mozilla.components.support.ktx.android.content.isMainProcess
import
mozilla.components.support.ktx.android.content.runOnlyInMainProcess
import
mozilla.components.support.locale.LocaleAwareApplication
...
...
@@ -43,7 +42,6 @@ import mozilla.components.support.webextensions.WebExtensionSupport
import
org.mozilla.fenix.StrictModeManager.enableStrictMode
import
org.mozilla.fenix.components.Components
import
org.mozilla.fenix.components.metrics.MetricServiceType
import
org.mozilla.fenix.ext.components
import
org.mozilla.fenix.ext.resetPoliciesAfter
import
org.mozilla.fenix.ext.settings
import
org.mozilla.fenix.perf.StorageStatsMetrics
...
...
@@ -116,7 +114,7 @@ open class FenixApplication : LocaleAwareApplication(), Provider {
setupCrashReporting
()
// We want the log messages of all builds to go to Android logcat
Log
.
addSink
(
Android
LogSink
())
Log
.
addSink
(
Fenix
LogSink
(
logsDebug
=
Config
.
channel
.
isDebug
))
}
@CallSuper
...
...
app/src/main/java/org/mozilla/fenix/FenixLogSink.kt
0 → 100644
View file @
a628f6f8
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package
org.mozilla.fenix
import
mozilla.components.support.base.log.Log
import
mozilla.components.support.base.log.sink.AndroidLogSink
import
mozilla.components.support.base.log.sink.LogSink
/**
* Fenix [LogSink] implementation that writes to Android's log, depending on settings.
*
* @param logsDebug If set to false, removes logging of debug logs.
*/
class
FenixLogSink
(
private
val
logsDebug
:
Boolean
=
true
)
:
LogSink
{
private
val
androidLogSink
=
AndroidLogSink
()
override
fun
log
(
priority
:
Log
.
Priority
,
tag
:
String
?,
throwable
:
Throwable
?,
message
:
String
?
)
{
if
(
priority
==
Log
.
Priority
.
DEBUG
&&
!
logsDebug
)
return
androidLogSink
.
log
(
priority
,
tag
,
throwable
,
message
)
}
}
app/src/test/java/org/mozilla/fenix/FenixLogSinkTest.kt
0 → 100644
View file @
a628f6f8
package
org.mozilla.fenix
import
android.util.Log
import
io.mockk.mockkStatic
import
io.mockk.unmockkStatic
import
io.mockk.verify
import
org.junit.After
import
org.junit.Before
import
org.junit.Test
class
FenixLogSinkTest
{
@Before
fun
setup
()
{
mockkStatic
(
Log
::
class
)
}
@After
fun
teardown
()
{
unmockkStatic
(
Log
::
class
)
}
@Test
fun
`GIVEN
we
'
re
in
a
release
build
WHEN
we
log
debug
statements
THEN
logs
should
not
be
forwarded`
()
{
val
logSink
=
FenixLogSink
(
false
)
logSink
.
log
(
mozilla
.
components
.
support
.
base
.
log
.
Log
.
Priority
.
DEBUG
,
"test"
,
message
=
"test"
)
verify
(
exactly
=
0
)
{
Log
.
println
(
Log
.
DEBUG
,
"test"
,
"test"
)
}
}
@Test
fun
`GIVEN
we
'
re
in
a
release
build
WHEN
we
log
error
statements
THEN
logs
should
be
forwarded`
()
{
val
logSink
=
FenixLogSink
(
false
)
logSink
.
log
(
mozilla
.
components
.
support
.
base
.
log
.
Log
.
Priority
.
ERROR
,
"test"
,
message
=
"test"
)
verify
(
exactly
=
1
)
{
Log
.
println
(
Log
.
ERROR
,
"test"
,
"test"
)
}
}
@Test
fun
`GIVEN
we
'
re
in
a
release
build
WHEN
we
log
warn
statements
THEN
logs
should
be
forwarded`
()
{
val
logSink
=
FenixLogSink
(
false
)
logSink
.
log
(
mozilla
.
components
.
support
.
base
.
log
.
Log
.
Priority
.
WARN
,
"test"
,
message
=
"test"
)
verify
(
exactly
=
1
)
{
Log
.
println
(
Log
.
WARN
,
"test"
,
"test"
)
}
}
@Test
fun
`GIVEN
we
'
re
in
a
release
build
WHEN
we
log
info
statements
THEN
logs
should
be
forwarded`
()
{
val
logSink
=
FenixLogSink
(
false
)
logSink
.
log
(
mozilla
.
components
.
support
.
base
.
log
.
Log
.
Priority
.
INFO
,
"test"
,
message
=
"test"
)
verify
(
exactly
=
1
)
{
Log
.
println
(
Log
.
INFO
,
"test"
,
"test"
)
}
}
@Test
fun
`GIVEN
we
'
re
in
a
debug
build
WHEN
we
log
debug
statements
THEN
logs
should
be
forwarded`
()
{
val
logSink
=
FenixLogSink
(
true
)
logSink
.
log
(
mozilla
.
components
.
support
.
base
.
log
.
Log
.
Priority
.
DEBUG
,
"test"
,
message
=
"test"
)
verify
(
exactly
=
1
)
{
Log
.
println
(
Log
.
DEBUG
,
"test"
,
"test"
)
}
}
}
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