在阅读了O'Reilly的一篇关于这个主题的文章之后,我想问Stack Overflow对这个问题的看法.
我使用的是Windows 7和python 2.7.我想将日志文件大小限制为5MB.我的应用程序在启动时写入日志文件,然后应用程序终止.当我的应用程序再次启动时,它将写入相同的日志文件.因此app不会持续运行.应用程序启动,处理和终止.
我的日志记录代码是:
import logging
import logging.handlers
logging.basicConfig(filename=logfile.log, level="info", format='%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
logging.info("*************************************************")
Run Code Online (Sandbox Code Playgroud)
我尝试使用RotatingFileHandler但它没有用
logging.handlers.RotatingFileHandler(logFile, mode='a', maxBytes=5*1024*1024, backupCount=2, encoding=None, delay=0)
Run Code Online (Sandbox Code Playgroud)
那么,我如何在python中强制执行文件大小限制?
我正在进行SQL Server 2008安装,其上运行着近15个数据库.现在由于空间的稀缺,我想将数据路径移动到另一个驱动器.这是什么最好的做法.请详细说明是否包含任何SQL命令,因为我对SQL Server管理相对较新.
注 - 我已经将SQL Server属性中的路径从SQL Management Studio 2008更改为新路径.但我还希望现有数据库驻留在新路径中.
我有几个日志包含所有以时间戳开头的行,以便以下工作按预期合并它们:
cat myLog1.txt myLog2.txt | sort -n > combined.txt
Run Code Online (Sandbox Code Playgroud)
问题是,myLog2.txt还可以包含没有时间戳的行(例如java堆栈跟踪).是否有一种简单的方法,没有任何自定义脚本仍然合并它们并保留多行内容?
示例myLog1.txt
11:48:18.825 [main] INFO org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
11:48:55.784 [main] INFO o.h.tool.hbm2ddl.SchemaUpdate - HHH000396: Updating schema
Run Code Online (Sandbox Code Playgroud)
示例myLog2.txt
11:48:35.377 [qtp1484319352-19] ERROR c.w.b.c.ControllerErrorHandler -
org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'org.joda.time.LocalDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat org.joda.time.LocalDate for value '[2013-03-26]'; nested exception is java.lang.IllegalArgumentException: Invalid format: " [2013-03-26]"
at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:68) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE]
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:45) ~[spring-beans-3.2.1.RELEASE.jar:3.2.1.RELEASE] …
Run Code Online (Sandbox Code Playgroud) 我在我的app目录中找不到'test.log'文件?
下面的代码在server.js中
var winston = require('winston'), mylogger = new (winston.Logger)({
transports: [
new (winston.transports.Console) (),
new (winston.transports.File) ({filename: 'test.log'})
]
});
mylogger.log('Hello world');
Run Code Online (Sandbox Code Playgroud)
我的app目录:
/
app/
config/
public/
server.js
Run Code Online (Sandbox Code Playgroud) 我尝试了所有方法来查找原因,但不确定是什么原因,尝试使用 jProfile,但没有得到任何结果,因为 cpu 已经达到 100%。
我在 Tomcat8 上的 amazon linux 上运行 Spring 应用程序(WAR 文件)。没有数据库操作,但是它访问了一个休息 api,用于在不同环境中运行的不同操作。有3 台服务器在beanstalk 中的负载平衡器后面运行时存在相同的问题。每小时平均518K请求,平均延迟为72.2 毫秒
我觉得代码本身没有太大问题
我刚刚尝试了一个命令 kill -3 pid (java process),并在 catalina.out 文件中得到了一些结果。我可以一次又一次地看到以下错误
"http-nio-8080-exec-13" #42 daemon prio=5 os_prio=0 tid=0x00007f0898005800 nid=0xfb2 waiting on condition [0x00007f0882dec000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000f1694f58> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at org.apache.tomcat.util.threads.TaskQueue.poll(TaskQueue.java:85)
at org.apache.tomcat.util.threads.TaskQueue.poll(TaskQueue.java:31)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1066)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at …
Run Code Online (Sandbox Code Playgroud) log-files ×6
logging ×3
database ×2
cat ×1
command-line ×1
data-files ×1
filehandler ×1
java ×1
log-analysis ×1
node.js ×1
python ×1
sorting ×1
sql ×1
tomcat8 ×1
winston ×1