首页 \ 问答 \ 为什么我的log4j.properties文件没有被使用?(Why isn't my log4j.properties file getting used?)

为什么我的log4j.properties文件没有被使用?(Why isn't my log4j.properties file getting used?)

我在当前目录中有一个log4j.properties文件,它指定了一些要在DEBUG级别记录的东西,以及其他所有东西作为INFO:

log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n

log4j.logger.com.xcski=DEBUG
log4j.logger.org.apache.nutch.protocol.http=DEBUG
log4j.logger.org.apache.nutch.fetcher.Fetcher=DEBUG

我从ant运行项目:

<target name="crawl" depends="compile">
  <java classname="com.xcski.nutch.crawler.Crawler"
        maxmemory="1000m" fork="true">
      <classpath refid="run.classpath"/>
  </java>
</target>

但由于某种原因,我得到的唯一输出来自LOG.info(),而不是LOG.debug。 我确定这是微不足道的,但我现在已经在墙上撞了一个小时了,我以为我会尝试这样做。


I have a log4j.properties file in my current directory that specifies some things to log at DEBUG level, and everything else as INFO:

log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n

log4j.logger.com.xcski=DEBUG
log4j.logger.org.apache.nutch.protocol.http=DEBUG
log4j.logger.org.apache.nutch.fetcher.Fetcher=DEBUG

And I run the project from ant:

<target name="crawl" depends="compile">
  <java classname="com.xcski.nutch.crawler.Crawler"
        maxmemory="1000m" fork="true">
      <classpath refid="run.classpath"/>
  </java>
</target>

But for some reason, the only output I get is from LOG.info(), not LOG.debug. I'm sure it's something trivial, but I've been beating my head against the wall for an hour now and I thought I'd try SO.


原文:https://stackoverflow.com/questions/1284952
更新时间:2022-01-13 17:01

最满意答案

我觉得你的记忆力很低。 这是该示例的修改版本,当您有许多任务时,它应该更好地工作。 它使用doSNOW而不是doParallel,因为doSNOW允许您在工作人员返回时使用combine函数处理结果。 此示例将这些结果写入文件以便使用更少的内存,但是它使用“.final”函数将结果读回到内存中,但如果没有足够的内存,则可以跳过该结果。

library(doSNOW)
library(tcltk)
nw <- 4  # number of workers
cl <- makeSOCKcluster(nw)
registerDoSNOW(cl)

x <- iris[which(iris[,5] != 'setosa'), c(1,5)]
niter <- 15e+6
chunksize <- 4000  # may require tuning for your machine
maxcomb <- nw + 1  # this count includes fobj argument
totaltasks <- ceiling(niter / chunksize)

comb <- function(fobj, ...) {
  for(r in list(...))
    writeBin(r, fobj)
  fobj
}

final <- function(fobj) {
  close(fobj)
  t(matrix(readBin('temp.bin', what='double', n=niter*2), nrow=2))
}

mkprogress <- function(total) {
  pb <- tkProgressBar(max=total,
                      label=sprintf('total tasks: %d', total))
  function(n, tag) {
    setTkProgressBar(pb, n,
      label=sprintf('last completed task: %d of %d', tag, total))
  }
}
opts <- list(progress=mkprogress(totaltasks))
resultFile <- file('temp.bin', open='wb')

r <-
  foreach(n=idiv(niter, chunkSize=chunksize), .combine='comb',
          .maxcombine=maxcomb, .init=resultFile, .final=final,
          .inorder=FALSE, .options.snow=opts) %dopar% {
    do.call('c', lapply(seq_len(n), function(i) {
      ind <- sample(100, 100, replace=TRUE)
      result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
      coefficients(result1)
    }))
  }

我包含了一个进度条,因为此示例需要几个小时才能执行。

请注意,此示例还使用iterators包中的idiv函数来增加每个任务中的工作量。 这种技术称为分块 ,通常可以提高并行性能。 然而,使用idiv任务索引,因为变量i现在是每任务索引而不是全局索引。 对于全局索引,您可以编写一个包装idiv的自定义迭代器:

idivix <- function(n, chunkSize) {
  i <- 1
  it <- idiv(n, chunkSize=chunkSize)
  nextEl <- function() {
    m <- nextElem(it)  # may throw 'StopIterator'
    value <- list(i=i, m=m)
    i <<- i + m
    value
  }
  obj <- list(nextElem=nextEl)
  class(obj) <- c('abstractiter', 'iter')
  obj
}

此迭代器发出的值是列表,每个列表包含起始索引和计数。 这是一个使用此自定义迭代器的简单foreach循环:

r <- 
  foreach(a=idivix(10, chunkSize=3), .combine='c') %dopar% {
    do.call('c', lapply(seq(a$i, length.out=a$m), function(i) {
      i
    }))
  }

当然,如果任务计算量足够大,您可能不需要分块,并且可以使用原始示例中的简单foreach循环。


I think you're running low on memory. Here's a modified version of that example that should work better when you have many tasks. It uses doSNOW rather than doParallel because doSNOW allows you to process the results with the combine function as they're returned by the workers. This example writes those results to a file in order to use less memory, however it reads the results back into memory at the end using a ".final" function, but you could skip that if you don't have enough memory.

library(doSNOW)
library(tcltk)
nw <- 4  # number of workers
cl <- makeSOCKcluster(nw)
registerDoSNOW(cl)

x <- iris[which(iris[,5] != 'setosa'), c(1,5)]
niter <- 15e+6
chunksize <- 4000  # may require tuning for your machine
maxcomb <- nw + 1  # this count includes fobj argument
totaltasks <- ceiling(niter / chunksize)

comb <- function(fobj, ...) {
  for(r in list(...))
    writeBin(r, fobj)
  fobj
}

final <- function(fobj) {
  close(fobj)
  t(matrix(readBin('temp.bin', what='double', n=niter*2), nrow=2))
}

mkprogress <- function(total) {
  pb <- tkProgressBar(max=total,
                      label=sprintf('total tasks: %d', total))
  function(n, tag) {
    setTkProgressBar(pb, n,
      label=sprintf('last completed task: %d of %d', tag, total))
  }
}
opts <- list(progress=mkprogress(totaltasks))
resultFile <- file('temp.bin', open='wb')

r <-
  foreach(n=idiv(niter, chunkSize=chunksize), .combine='comb',
          .maxcombine=maxcomb, .init=resultFile, .final=final,
          .inorder=FALSE, .options.snow=opts) %dopar% {
    do.call('c', lapply(seq_len(n), function(i) {
      ind <- sample(100, 100, replace=TRUE)
      result1 <- glm(x[ind,2]~x[ind,1], family=binomial(logit))
      coefficients(result1)
    }))
  }

I included a progress bar since this example takes several hours to execute.

Note that this example also uses the idiv function from the iterators package to increase the amount of work in each of the tasks. This technique is called chunking, and often improves the parallel performance. However, using idiv messes up the task indices, since the variable i is now a per-task index rather than a global index. For a global index, you can write a custom iterator that wraps idiv:

idivix <- function(n, chunkSize) {
  i <- 1
  it <- idiv(n, chunkSize=chunkSize)
  nextEl <- function() {
    m <- nextElem(it)  # may throw 'StopIterator'
    value <- list(i=i, m=m)
    i <<- i + m
    value
  }
  obj <- list(nextElem=nextEl)
  class(obj) <- c('abstractiter', 'iter')
  obj
}

The values emitted by this iterator are lists, each containing a starting index and a count. Here's a simple foreach loop that uses this custom iterator:

r <- 
  foreach(a=idivix(10, chunkSize=3), .combine='c') %dopar% {
    do.call('c', lapply(seq(a$i, length.out=a$m), function(i) {
      i
    }))
  }

Of course, if the tasks are compute intensive enough, you may not need chunking and can use a simple foreach loop as in the original example.

相关问答

更多
  • byrow = F旁边有一个“)”,即 foreach(i=1:6,.combine=matrix(0,6,5,byrow=F)) %dopar% Mat.corr[i,]=cop.theta(index,EXPR,QT=survp[,i]) 应该修复此错误。 但是,请注意, foreach循环内的mat.corr[i,]=...不会将cop.theta操作产生的值写入此特定行,只要您并行运行循环 - 这只是可以使用单核foreach 。 这意味着,您必须使用foreach()内部的.combine或 ...
  • 好吧,我想通过调用foreach和%dopar%得到它: # Libraries --------------------------------------------------------------- if (!require("pacman")) install.packages("pacman") pacman::p_load(lakemorpho,rgdal,maptools,sp,doParallel,foreach, doParallel) # Data - ...
  • 问题很可能是您没有为每个工作者调用library(xts) 。 你不会说你使用的后端,所以我不能100%确定。 如果这是问题,那么这段代码将修复它: list <- foreach(i=1:ncol(combs)) %dopar% { library(xts) tmp_triple <- combs[,i] p1<-data[tmp_triple[[1]]][[1]] p2<-data[tmp_triple[[2]]][[1]] p3<-data[tmp_tripl ...
  • 我同意问题是由于停止了主控并继续使用处于损坏状态的集群对象造成的。 在与群集工作人员的套接字连接中可能存在未读数据,导致主人和工作人员不同步。 您甚至可能在调用stopCluster遇到问题,因为它也会写入套接字连接。 如果您确实停止了主设备,我会建议调用stopCluster然后创建另一个集群对象,但请记住,以前的工作人员可能无法始终正常退出。 最好验证工作进程是否已经死亡,如果不是,则手动杀死它们。 I agree that the problem was caused by stopping the ...
  • 您需要注册一个并行后端。 做类似的事情 library(doParallel) registerDoParallel(cores=4) You need to register a parallel backend. Do something like library(doParallel) registerDoParallel(cores=4)
  • 我觉得你的记忆力很低。 这是该示例的修改版本,当您有许多任务时,它应该更好地工作。 它使用doSNOW而不是doParallel,因为doSNOW允许您在工作人员返回时使用combine函数处理结果。 此示例将这些结果写入文件以便使用更少的内存,但是它使用“.final”函数将结果读回到内存中,但如果没有足够的内存,则可以跳过该结果。 library(doSNOW) library(tcltk) nw <- 4 # number of workers cl <- makeSOCKcluster(nw) r ...
  • 使用foreach或类似工具进行并行化是有效的,因为您有多个CPU(或具有多个内核的CPU),可以同时处理多个任务。 GPU也有多个核心,但这些核心已经用于并行处理单个任务 。 因此,如果您想进一步并行化,则需要多个GPU 。 但是,请记住,GPU仅比某些类型的应用程序更快。 使用大型矩阵的矩阵运算就是一个很好的例子! 有关一个特定示例的最新比较,请参见此处的性能部分。 因此,您可以考虑GPU是否适合您。 此外:文件IO将始终通过CPU。 Parallelization with foreach or si ...
  • 因此,我们可以调用“您正在迭代的事物的数量”,您可以为不同的进程动态设置它们 编写并行化脚本可能看起来像这样 if(length(iter)==1){ Result <- #some function } else { cl <- makeCluster(iter) registerDoParallel(cl) Result <- foreach(z=1:iter) %dopar% { # some function } stopCluster(cl) } 如果iter为 ...
  • 我无法重现你的问题。 这对我来说很好: matrixA <- matrix(runif(36), 6) matrixB <- matrix(runif(36), 6) cl <- parallel::makeCluster(4) doParallel::registerDoParallel(cl) library(foreach) p.values.res<-foreach(i=seq(dim(matrixA)[1])) %dopar% var.test(matrixA[i,],matrixB[i,] ...
  • 我注意到的一件坏事是你附加了param字符串变量。 这将在您的循环中创建大量扔掉的对象。 而是使用字符串生成器。 StringBuilder builder = new StringBuilder() foreach (Busqueda.CodDesCIE elemResult in result.listaCodDesCIE) { .. builder.Append(" IdBuzon_Detalle:").Append( elemResultExterno.IdBuzonDetalle); ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)