This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Log Utility for Android, and developers could change log level…
… using http://editor.weex.io/vue/8fb63b977fad1bf816b9a9ad79a43fbd (#2540) 1. Add ConsoleLogModule, developers could change log using javascript. 1. Print log to logcat and devtool only if WXEnviroment.sLogLevel is bigger than the log being printed. 1. Change WXEnviroment.sLogLevel to INFO under debug apk, change it to WARN otherwise. Before this change WXEnvironment.sApplication was always null when initializing WXEnviroment.sLogLevel, so WXEnviroment.sLogLevel was always debug regardless it's actually debuggable or not. 1. Enable LogI no matter it's debuggable or not. 1. Change the value of LogLevel.value, which should have no influence.
- Loading branch information
Showing
6 changed files
with
102 additions
and
35 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
76 changes: 76 additions & 0 deletions
76
android/sdk/src/main/java/com/taobao/weex/ui/module/ConsoleLogModule.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,76 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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 com.taobao.weex.ui.module; | ||
|
||
import android.support.annotation.Nullable; | ||
import android.support.v4.util.ArrayMap; | ||
import android.text.TextUtils; | ||
import com.taobao.weex.WXEnvironment; | ||
import com.taobao.weex.annotation.JSMethod; | ||
import com.taobao.weex.bridge.JSCallback; | ||
import com.taobao.weex.common.WXModule; | ||
import com.taobao.weex.utils.LogLevel; | ||
import java.util.Map; | ||
|
||
|
||
public class ConsoleLogModule extends WXModule { | ||
|
||
@JSMethod(uiThread = false) | ||
public void switchLogLevel(@Nullable String logLevel, @Nullable JSCallback callback) { | ||
LogLevel logLevelEnum = getLogLevel(logLevel); | ||
Map<String, String> ret = new ArrayMap<>(); | ||
if (logLevelEnum != null) { | ||
WXEnvironment.sLogLevel = logLevelEnum; | ||
ret.put("status", "success"); | ||
} else { | ||
ret.put("status", "failure"); | ||
} | ||
|
||
if (callback != null) { | ||
callback.invoke(ret); | ||
} | ||
|
||
} | ||
|
||
private @Nullable LogLevel getLogLevel(@Nullable String logLevel) { | ||
LogLevel logLevelEnum = null; | ||
if(!TextUtils.isEmpty(logLevel)){ | ||
switch (logLevel){ | ||
case "off": | ||
logLevelEnum = LogLevel.OFF; | ||
break; | ||
case "error": | ||
logLevelEnum = LogLevel.ERROR; | ||
break; | ||
case "warning": | ||
logLevelEnum = LogLevel.WARN; | ||
break; | ||
case "info": | ||
logLevelEnum = LogLevel.INFO; | ||
break; | ||
case "debug": | ||
logLevelEnum = LogLevel.DEBUG; | ||
break; | ||
} | ||
} | ||
return logLevelEnum; | ||
} | ||
|
||
|
||
} |
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