-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Created LoggingPolicy and LogLevel * Created DefaultLoggingPolicy * Making library logging policy configurable * Ussing logging policy in AndroidLogger * Not creating logs when the agent is not initialized as part of the default logging policy * Enhancing LoggingPolicy convenience methods * Updating configuration.asciidoc to include new library logging policy config * Update docs/configuration.asciidoc Co-authored-by: Brandon Morelli <[email protected]> * Updating logging policy docs --------- Co-authored-by: Brandon Morelli <[email protected]>
- Loading branch information
1 parent
1b3e115
commit 4f94091
Showing
13 changed files
with
471 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
android-sdk/src/main/java/co/elastic/apm/android/sdk/configuration/logging/LogLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.apm.android.sdk.configuration.logging; | ||
|
||
public enum LogLevel { | ||
TRACE(0), DEBUG(1), INFO(2), WARN(3), ERROR(4); | ||
|
||
public final int value; | ||
|
||
LogLevel(int value) { | ||
this.value = value; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...oid-sdk/src/main/java/co/elastic/apm/android/sdk/configuration/logging/LoggingPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.apm.android.sdk.configuration.logging; | ||
|
||
import co.elastic.apm.android.sdk.configuration.logging.impl.DefaultLoggingPolicy; | ||
import co.elastic.apm.android.sdk.configuration.logging.impl.SimpleLoggingPolicy; | ||
|
||
/** | ||
* Defines the internal logging behavior of this library. | ||
*/ | ||
public interface LoggingPolicy { | ||
|
||
/** | ||
* Provides the default logging policy which will log all the {@link LogLevel}s on debuggable applications | ||
* and only logs from level INFO and above for non-debuggable applications. | ||
* <p> | ||
* No logs will be created until the Agent is initialized. | ||
*/ | ||
static LoggingPolicy getDefault() { | ||
return DefaultLoggingPolicy.create(); | ||
} | ||
|
||
/** | ||
* Convenience method for creating an enabled logging policy with a static minimum level. | ||
* | ||
* @param minimumLevel - The minimum {@link LogLevel}, all the logs with this level and above will get printed, others will be ignored. | ||
*/ | ||
static LoggingPolicy enabled(LogLevel minimumLevel) { | ||
return new SimpleLoggingPolicy(true, minimumLevel); | ||
} | ||
|
||
/** | ||
* Convenience method for creating a policy that disables all internal logs. | ||
*/ | ||
static LoggingPolicy disabled() { | ||
return new SimpleLoggingPolicy(false, LogLevel.TRACE); | ||
} | ||
|
||
/** | ||
* Whether logging in general is enabled or not. This value will be checked before the log level. | ||
*/ | ||
boolean isEnabled(); | ||
|
||
/** | ||
* If logging is enabled, this value will be checked later to filter which logs will | ||
* get printed. Logs with at least the level provided here or higher will pass, other ones (below the level provided here) will be ignored. | ||
*/ | ||
LogLevel getMinimumLevel(); | ||
} |
60 changes: 60 additions & 0 deletions
60
...main/java/co/elastic/apm/android/sdk/configuration/logging/impl/DefaultLoggingPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.apm.android.sdk.configuration.logging.impl; | ||
|
||
import co.elastic.apm.android.sdk.ElasticApmAgent; | ||
import co.elastic.apm.android.sdk.configuration.logging.LogLevel; | ||
import co.elastic.apm.android.sdk.configuration.logging.LoggingPolicy; | ||
import co.elastic.apm.android.sdk.internal.services.Service; | ||
import co.elastic.apm.android.sdk.internal.services.ServiceManager; | ||
import co.elastic.apm.android.sdk.internal.services.appinfo.AppInfoService; | ||
import co.elastic.apm.android.sdk.internal.utilities.providers.LazyProvider; | ||
import co.elastic.apm.android.sdk.internal.utilities.providers.Provider; | ||
|
||
public class DefaultLoggingPolicy implements LoggingPolicy { | ||
|
||
private final Provider<Boolean> appIsDebuggable; | ||
private final Provider<Boolean> agentIsInitialized; | ||
|
||
public static DefaultLoggingPolicy create() { | ||
final Provider<Boolean> agentIsInitialized = ElasticApmAgent::isInitialized; | ||
return new DefaultLoggingPolicy(LazyProvider.of(() -> { | ||
if (!agentIsInitialized.get()) { | ||
return false; | ||
} | ||
AppInfoService service = ServiceManager.get().getService(Service.Names.APP_INFO); | ||
return service.isInDebugMode(); | ||
}), agentIsInitialized); | ||
} | ||
|
||
public DefaultLoggingPolicy(Provider<Boolean> appIsDebuggable, Provider<Boolean> agentIsInitialized) { | ||
this.appIsDebuggable = appIsDebuggable; | ||
this.agentIsInitialized = agentIsInitialized; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return agentIsInitialized.get(); | ||
} | ||
|
||
@Override | ||
public LogLevel getMinimumLevel() { | ||
return (appIsDebuggable.get()) ? LogLevel.DEBUG : LogLevel.INFO; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../main/java/co/elastic/apm/android/sdk/configuration/logging/impl/SimpleLoggingPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package co.elastic.apm.android.sdk.configuration.logging.impl; | ||
|
||
import co.elastic.apm.android.sdk.configuration.logging.LogLevel; | ||
import co.elastic.apm.android.sdk.configuration.logging.LoggingPolicy; | ||
|
||
public final class SimpleLoggingPolicy implements LoggingPolicy { | ||
private final boolean isEnabled; | ||
private final LogLevel minimumLevel; | ||
|
||
public SimpleLoggingPolicy(boolean isEnabled, LogLevel minimumLevel) { | ||
this.isEnabled = isEnabled; | ||
this.minimumLevel = minimumLevel; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return isEnabled; | ||
} | ||
|
||
@Override | ||
public LogLevel getMinimumLevel() { | ||
return minimumLevel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.