小编bal*_*man的帖子

在运行时更改 Go lang slog 的日志级别

使用 Go slog 日志记录包("log/slog"),我正在寻找一种在运行时更改记录器的日志级别的方法?
是否可以?我花了几个小时玩它,但找不到办法做到这一点。

更新 1 - 运行具有 3 个记录器的应用程序并使用 HTTP 更改级别

以下是我根据彼得的回答编写的代码。我像这样进行 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)

go

7
推荐指数
1
解决办法
4300
查看次数

NoSuchFieldError:INCLUDE_ALL

我在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)

java google-app-engine spring maven jersey-2.0

5
推荐指数
2
解决办法
6047
查看次数

Android Studio无法连接到SVN服务器 - SSL握手失败

我在使用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配置:

  1. 一般:使用命令行客户端:/ sw/bin/svn(它指向1.8.10 SVN客户端)
  2. 一般:使用系统默认的Subversion配置目录:〜/ .subversion
  3. 网络:TLSv1

请指教

svn ssl assembla android-studio

5
推荐指数
1
解决办法
5559
查看次数

aiobotocore - 导入错误:无法导入名称“InvalidIMDSEndpointError”

下面的代码引发导入异常

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)

python-3.x boto3 ubuntu-18.04 python-s3fs

4
推荐指数
2
解决办法
3414
查看次数

如何在不使用.pop()或.remove()的情况下从项目列表中删除首次出现的特定项目

我有一个列表,我们称它为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 list

1
推荐指数
1
解决办法
93
查看次数

为什么使用 os.popen 时最后一行是空的

我正在使用这个 Python (Python 3) 代码,以便获取所有主题的列表

\n

作为:

\n
more test.py\n\nlist = os.popen(" kafka-topics.sh \xe2\x80\x93zookeeper zoo_server:2181 --list | sed '/^[[:space:]]*$/d'  ").read().split('\\n')\nprint (list)\n
Run 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]\n
Run Code Online (Sandbox Code Playgroud)\n

所以最后一个单词实际上是空的,因为在单引号之间,因为\xe2\x80\x98 \xe2\x80\x98我们没有主题名称

\n

这很奇怪,因为在行中我使用 sed -sed '/^[[:space:]]*$/d'来删除空行,并且当我运行以下命令时实际上不是空行

\n
kafka-topics.sh \xe2\x80\x93zookeeperzoo_server:2181 --list | sed '/^[[:space:]]*$/d'  \n
Run Code Online (Sandbox Code Playgroud)\n

我的 Python 行有什么问题吗?

\n

例如,当我跑步时

\n
kafka-topics.sh \xe2\x80\x93zookeeper zoo_server:2181 --list | sed '/^[[:space:]]*$/d'\n\ntopic1\ntopic2\ntopic3\n.\n.\n.\n
Run Code Online (Sandbox Code Playgroud)\n

python linux python-3.x apache-kafka

1
推荐指数
1
解决办法
162
查看次数

Android相对布局 - 将图像对齐到右侧

我想有以下布局:
在此输入图像描述

布局由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的大小?

android android-layout

-1
推荐指数
2
解决办法
9329
查看次数