0

Scala newb here (it's my 2nd day of using it). I want to get log4j logging working in my Scala script. The script and the results are below, any ideas as to what's going wrong?

[sean@ibmp2 pybackup]$ cat backup.scala
import org.apache.log4j._

val log = LogFactory.getLog()

log.info("started backup")
[sean@ibmp2 pybackup]$ scala -cp log4j-1.2.16.jar:. backup.scala
/home/sean/projects/personal/pybackup/backup.scala:1: error: value apache is not a member of package org
import org.apache.log4j._
           ^
one error found
fred basset
  • 9,774
  • 28
  • 88
  • 138

5 Answers5

2

I reproduce it under Windows: delimiter of '-classpath' must be ';' there (not ':'). Are you use cygwin or some sort of unix emulator?

But Scala script works anywhere without current dir in classpath. Try to use:

$ scala -cp log4j-1.2.16.jar backup.scala

JFI: LogFactory is a class of slf4j library (not log4j).

UPDATE

Another possible case: broken jar in classpath, maybe during download or something else. Scala interpreter does report only about unavailable member of the package.

$ echo "qwerty" > example.jar
$ scala -cp example.jar backup.scala
backup.scala:1: error: value apache is not a member of package org
...

Need to inspect content of the jar-file:

$ jar -tf log4j-1.2.16.jar
...
org/apache/log4j/Appender.class
...
andy legkiy
  • 203
  • 3
  • 7
1

Did you remember to put log4j.jar in your classpath?

Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
  • I have the log4j jar file in the same directory as my .scala source, and I tried running scala with -cp log4j-x.x.jar as an argument, didn't seem to make any difference – fred basset Jan 09 '11 at 21:25
0

Had Similar issue when started doing Scala Development using Eclipse, doing a clean build solved the problem.

Guess the Scala tools are not matured et.

mailboat
  • 1,077
  • 9
  • 17
-1

Instead of using log4j directly, you might try using Configgy. It's the Scala Way™ to work with log4j, as well as configuration files. It also plays nicely with SBT and Maven.

Jeremy
  • 205
  • 3
  • 8
-1

I asked and answered this question myself, have a look:

Put it under src/main/resources/logback.xml. It will be copied to the right location when SBT is doing the artifact assembly.

Community
  • 1
  • 1
jpswain
  • 14,642
  • 8
  • 58
  • 63