使用 Go slog 日志记录包("log/slog"),我正在寻找一种在运行时更改记录器的日志级别的方法?
是否可以?我花了几个小时玩它,但找不到办法做到这一点。
以下是我根据彼得的回答编写的代码。我像这样进行 HTTP 调用
http://localhost:8080/changeLogLevel?logger=TCP&level=ERROR。
package main
import (
"log"
"log/slog"
"net/http"
"os"
"strings"
"time"
)
func main() {
// Create a LevelVar variable and initialize it to DEBUG.
// Create the template logger with info
tcpLvl := new(slog.LevelVar)
tcpLvl.Set(slog.LevelDebug)
dbLvl := new(slog.LevelVar)
dbLvl.Set(slog.LevelDebug)
mqLvl := new(slog.LevelVar)
mqLvl.Set(slog.LevelDebug)
tcpLogger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: tcpLvl,
}))
mqLogger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: mqLvl,
}))
// Create the …Run Code Online (Sandbox Code Playgroud) 我在GAE上将Jersey和Spring一起使用。
我得到以下异常:
Uncaught exception from servlet
java.lang.NoSuchFieldError: INCLUDE_ALL
at org.glassfish.jersey.server.ResourceConfig$State.<init> (ResourceConfig.java:110)
at org.glassfish.jersey.server.ResourceConfig.<init>(ResourceConfig.java:351)
at org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig.<init>(ResourceConfig.java:1014)
at org.glassfish.jersey.server.ResourceConfig.forApplicationClass(ResourceConfig.java:325)
at org.glassfish.jersey.servlet.WebComponent.createResourceConfig(WebComponent.java:442)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:294)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:167)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:349)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:219)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:194)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:724)
Run Code Online (Sandbox Code Playgroud)
查看Jersey代码,我看到这是抛出异常的地方:
public State() {
super(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL);
Run Code Online (Sandbox Code Playgroud)
查看“ ComponentBag”,我可以看到在运行时找不到的公共字段。
public static final …Run Code Online (Sandbox Code Playgroud) 我在使用Android Studio 1.01连接到SVN服务器时遇到问题.
当我尝试浏览远程SVN存储库时,出现以下错误:
Subversion :(访问URL:https://subversion.assembla.com/svn/whozeincharge)收到致命警报:handshake_failure请检查Subversion SSL设置(设置|版本控制| Subversion |网络)也许您应该手动指定SSL协议 - SSLv3或使用TLSv1
我的SVN服务器托管在www.assembla.com
Assembla团队阻止了与SVN服务器的基于SSL的连接,并要求我使用TLS.
请参阅我与assembla支持的对话.
使用SVN CLI,我可以毫无问题地连接到服务器.
我的SVN客户端版本是:1.8.10
我的Mac信息:
system_profiler SPSoftwareDataType软件:
系统软件概述:
系统版本:OS X 10.9.5(13F34)
内核版本:Darwin 13.4.0
启动卷:Macintosh HD
启动模式:普通
计算机名称:[name goes here]
用户名:[name goes here>]
删除目录〜/ .subversion/auth/svn.ssl.server
并重新启动Android Studio后,我能够浏览远程存储库(使用Android Studio),没有任何问题.
过了一会儿,ssl握手错误又回来了,在文件系统上创建了文件夹〜/ .subversion/auth/svn.ssl.server.
我的Android Studio SVN配置:
请指教
下面的代码引发导入异常
import s3fs
fs = s3fs.S3FileSystem(anon=False)
Run Code Online (Sandbox Code Playgroud)
例外
Traceback (most recent call last):
File "issue.py", line 1, in <module>
import s3fs
File "/home/ubuntu/.local/lib/python3.6/site-packages/s3fs/__init__.py", line 1, in <module>
from .core import S3FileSystem, S3File
File "/home/ubuntu/.local/lib/python3.6/site-packages/s3fs/core.py", line 14, in <module>
import aiobotocore
File "/home/ubuntu/.local/lib/python3.6/site-packages/aiobotocore/__init__.py", line 1, in <module>
from .session import get_session, AioSession
File "/home/ubuntu/.local/lib/python3.6/site-packages/aiobotocore/session.py", line 6, in <module>
from .client import AioClientCreator, AioBaseClient
File "/home/ubuntu/.local/lib/python3.6/site-packages/aiobotocore/client.py", line 12, in <module>
from .utils import AioS3RegionRedirector
File "/home/ubuntu/.local/lib/python3.6/site-packages/aiobotocore/utils.py", line 10, in <module>
from botocore.exceptions import …Run Code Online (Sandbox Code Playgroud) 我有一个列表,我们称它为l = [1,2,3,7,8,9,10,7]。给定该列表l,我尝试不使用.pop()或.remove()内置函数来删除数字7的第一次出现。
我试过了
def remove_item(l, item_to_remove):
newlst = []
for item in l:
if item != item_to_remove:
newlst.append(item)
return newlst
Run Code Online (Sandbox Code Playgroud)
但是,这将删除我尝试删除的项目的所有实例,而实际上我只想删除该特定项目的第一个实例。有没有人对如何做到这一点有一些提示?
我正在使用这个 Python (Python 3) 代码,以便获取所有主题的列表
\n作为:
\nmore test.py\n\nlist = os.popen(" kafka-topics.sh \xe2\x80\x93zookeeper zoo_server:2181 --list | sed '/^[[:space:]]*$/d' ").read().split('\\n')\nprint (list)\nRun Code Online (Sandbox Code Playgroud)\n当我运行 python 脚本时,我注意到最后一行如下所示
\n\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6\n\xe2\x80\xa6\xe2\x80\xa6\xe2\x80\xa6.'topic32', 'topic33', 'topic34 , \xe2\x80\x98 \xe2\x80\x98]\nRun Code Online (Sandbox Code Playgroud)\n所以最后一个单词实际上是空的,因为在单引号之间,因为\xe2\x80\x98 \xe2\x80\x98我们没有主题名称
这很奇怪,因为在行中我使用 sed -sed '/^[[:space:]]*$/d'来删除空行,并且当我运行以下命令时实际上不是空行
kafka-topics.sh \xe2\x80\x93zookeeperzoo_server:2181 --list | sed '/^[[:space:]]*$/d' \nRun Code Online (Sandbox Code Playgroud)\n我的 Python 行有什么问题吗?
\n例如,当我跑步时
\nkafka-topics.sh \xe2\x80\x93zookeeper zoo_server:2181 --list | sed '/^[[:space:]]*$/d'\n\ntopic1\ntopic2\ntopic3\n.\n.\n.\nRun Code Online (Sandbox Code Playgroud)\n 我想有以下布局:

布局由3个图像(Image1,Image2,Image3)和
2个TextView(Text1和Text2)组成,
Image2和Image3是可选的.
想法是使用具有以下约束的RelativeLayout:
- Text1位于image1
的右侧
- Text2位于image1的右侧- Text2位于Text1的下方
- Image2 位于Text1 的右侧(并且右侧对齐)
- Image3在Text2的右侧(并向右对齐)
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<ImageView
android:id="@+id/Image1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="6dip" />
<TextView
android:id="@+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/Image1"
android:textSize="16sp" />
<TextView
android:id="@+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/Text1"
android:layout_toRightOf="@id/image1"
android:singleLine="true"
android:textSize="12sp" />
<ImageView
android:id="@+id/Image2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/Text1" />
<ImageView
android:id="@+id/Image3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/Image2"
android:layout_toRightOf="@id/Text2" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
问题:
至于现在,我无法将Image2和Image3对齐到右边.
如何控制Image1和Image2的大小?
python ×2
python-3.x ×2
android ×1
apache-kafka ×1
assembla ×1
boto3 ×1
go ×1
java ×1
jersey-2.0 ×1
linux ×1
list ×1
maven ×1
python-s3fs ×1
spring ×1
ssl ×1
svn ×1
ubuntu-18.04 ×1