我一直在做研究,我很难完成我希望实现的目标.目前,这就是我所拥有的(testlog.py)
import logging
import logging.handlers
filename = "example.log"
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler = logging.handlers.RotatingFileHandler(filename, mode = 'w', backupCount = 5)
handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)
logger.addHandler(handler)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
for i in range(10):
logger.debug("testx") #where I alternate x from 1 thru 9 to see output
Run Code Online (Sandbox Code Playgroud)
它目前成功打印到控制台和example.log,这是我想要的.
每次运行它时,它都会创建一个新文件并替换旧的example.log,如下所示:
跟着跑 logger.debug("test1")
example.log包含test1 10次
跟着跑 logger.debug("test2")
它重写example.log以包含test2 10次等...
但是,我希望每次运行程序时代码都能生成一个新的日志文件
example.log
example.log1
example.log2
...
example.log5
总之,我希望这个文件将日志消息打印到控制台,日志文件,每当我运行程序时,我想要一个新的日志文件(最多*.5).谢谢!
我很难理解 BitSet.valueOf(bytearray)
我有以下代码:
byte[] a = new byte[]{(byte) 0x2D, (byte) 0x04};
//binary => 0010 1101 0000 0100
BitSet bs = BitSet.valueOf(a);
System.out.println(bs);
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我一个输出{0, 2, 3, 5, 10}。为什么?
我认为它应该返回为真或保持 1 的索引,向后应该是{2, 8, 10, 11, 13}.
这似乎是一个简单的问题,但我很困惑.
byte[] bArray = new byte[]{(byte) (0x80 & 0xff)};
System.out.println(bArray[0]);
Run Code Online (Sandbox Code Playgroud)
我的输出是-128.为什么?我怎样才能重写这个,以便字节数组包含128?我以为是0xff无条件的.谢谢你的帮助!