本文整理汇总了Scala中org.apache.log4j.Level类的典型用法代码示例。如果您正苦于以下问题:Scala Level类的具体用法?Scala Level怎么用?Scala Level使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Level类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MyApp
//设置package包名称以及导入依赖的类
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import org.apache.log4j.{Level, Logger}
object MyApp {
def main(args: Array[String]) {
val rootLogger = Logger.getRootLogger()
rootLogger.setLevel(Level.ERROR)
val file = args(0)
val conf = new SparkConf(true).setAppName("My Application")
val sc = new SparkContext(conf)
val tf = sc.textFile(file,2)
val splits = tf.flatMap(line => line.split(" ")).map(word =>(word,1))
val counts = splits.reduceByKey((x,y)=>x+y)
System.out.println(counts.collect().mkString(", "))
sc.stop()
}
}
示例2: KMeansCases
//设置package包名称以及导入依赖的类
import org.apache.spark.SparkContext
import org.apache.spark.mllib.clustering.{KMeans, KMeansModel}
import org.apache.spark.mllib.linalg.Vectors
import org.apache.log4j.{Level, Logger}
class KMeansCases(sc: SparkContext, dataFile: String, numOfCenters: Int, maxIterations:Int) {
//hide logger from console
Logger.getLogger("org").setLevel(Level.OFF)
Logger.getLogger("akka").setLevel(Level.OFF)
val data = sc.textFile(dataFile)
val parsedData = data.map(s => Vectors.dense(s.split('\t').map(_.toDouble))).cache()
def KMeansInitialCenters() = {
val initStartTime = System.nanoTime()
val centers = new KMeansInitialization().run(sc, dataFile, numOfCenters)
val initTimeInSeconds = (System.nanoTime() - initStartTime) / 1e9
println(s"Initialization to find centers took " + "%.3f".format(initTimeInSeconds) + " seconds.")
val initStartTime1 = System.nanoTime()
val model = new KMeansModel(centers)
val clusterModel = new KMeans().setK(numOfCenters).setMaxIterations(maxIterations).setInitialModel(model).run(parsedData)
val initTimeInSeconds1 = (System.nanoTime() - initStartTime1) / 1e9
println(s"Initialization with custom took " + "%.3f".format(initTimeInSeconds1) + " seconds.")
println("\nnumber of points per cluster")
clusterModel.predict(parsedData).map(x=>(x,1)).reduceByKey((a,b)=>a+b).foreach(x=>println(x._2))
}
def KMeansParallel() = {
val initStartTime = System.nanoTime()
val clusterModel = KMeans.train(parsedData, numOfCenters, maxIterations, 1, KMeans.K_MEANS_PARALLEL)
val initTimeInSeconds = (System.nanoTime() - initStartTime) / 1e9
println(s"Initialization with KMeansParaller took " + "%.3f".format(initTimeInSeconds) + " seconds.")
println("number of points per cluster")
clusterModel.predict(parsedData).map(x=>(x,1)).reduceByKey((a,b)=>a+b).foreach(x=>println(x._2))
}
def KMeansRandom() = {
val initStartTime = System.nanoTime()
val clusterModel = KMeans.train(parsedData, numOfCenters, maxIterations, 1, KMeans.RANDOM)
val initTimeInSeconds = (System.nanoTime() - initStartTime) / 1e9
println(s"Initialization with KMeasRandom took " + "%.3f".format(initTimeInSeconds) + " seconds.")
println("number of points per cluster")
clusterModel.predict(parsedData).map(x=>(x,1)).reduceByKey((a,b)=>a+b).foreach(x=>println(x._2))
}
}
示例3: driver
//设置package包名称以及导入依赖的类
import java.io._
import utils._
import SMOTE._
import org.apache.log4j.Logger
import org.apache.log4j.Level
import breeze.linalg._
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import scala.collection.mutable.{ArrayBuffer,Map}
object driver {
def main(args: Array[String]) {
val conf = new SparkConf()
val options = args.map { arg =>
arg.dropWhile(_ == '-').split('=') match {
case Array(opt, v) => (opt -> v)
case Array(opt) => (opt -> "")
case _ => throw new IllegalArgumentException("Invalid argument: "+arg)
}
}.toMap
val rootLogger = Logger.getRootLogger()
rootLogger.setLevel(Level.ERROR)
val sc = new SparkContext(conf)
// read in general inputs
val inputDirectory = options.getOrElse("inputDirectory","")
val outputDirectory = options.getOrElse("outputDirectory","")
val numFeatures = options.getOrElse("numFeatures","0").toInt
val oversamplingPctg = options.getOrElse("oversamplingPctg","1.0").toDouble
val kNN = options.getOrElse("K","5").toInt
val delimiter = options.getOrElse("delimiter",",")
val numPartitions = options.getOrElse("numPartitions","20").toInt
SMOTE.runSMOTE(sc, inputDirectory, outputDirectory, numFeatures, oversamplingPctg, kNN, delimiter, numPartitions)
println("The algorithm has finished running")
sc.stop()
}
}
示例4: LogUtils
//设置package包名称以及导入依赖的类
package org.iamShantanu101.spark.SentimentAnalyzer.utils
import org.apache.log4j.{Level, Logger}
import org.apache.spark.{Logging, SparkContext}
object LogUtils extends Logging {
def setLogLevels(sparkContext: SparkContext) {
sparkContext.setLogLevel(Level.WARN.toString)
val log4jInitialized = Logger.getRootLogger.getAllAppenders.hasMoreElements
if (!log4jInitialized) {
logInfo(
"""Setting log level to [WARN] for streaming executions.
|To override add a custom log4j.properties to the classpath.""".stripMargin)
Logger.getRootLogger.setLevel(Level.WARN)
}
}
}
示例5: Logging
//设置package包名称以及导入依赖的类
package org.hpi.esb.commons.util
import org.apache.log4j.{Level, Logger}
trait Logging {
var logger: Logger = Logger.getLogger("senskaLogger")
}
object Logging {
def setToInfo() {
Logger.getRootLogger.setLevel(Level.INFO)
}
def setToDebug() {
Logger.getRootLogger.setLevel(Level.DEBUG)
}
}
示例6: PrepArgParser
//设置package包名称以及导入依赖的类
import org.apache.log4j.{Level, Logger}
import org.apache.spark.mllib.util.MLUtils
import org.apache.spark.{SparkConf, SparkContext}
import utils.Utils
import scala.util.Try
import scalax.file.Path
class PrepArgParser(arguments: Seq[String]) extends org.rogach.scallop.ScallopConf(arguments) {
val dataset = opt[String](required = true, short = 'd',
descr = "absolute address of the libsvm dataset. This must be provided.")
val partitions = opt[Int](required = false, default = Some(4), short = 'p', validate = (0 <),
descr = "Number of spark partitions to be used. Optional.")
val dir = opt[String](required = true, default = Some("../results/"), short = 'w', descr = "working directory where results " +
"are stored. Default is \"../results\". ")
val method = opt[String](required = true, short = 'm',
descr = "Method can be either \"Regression\" or \"Classification\". This must be provided")
verify()
}
object PrepareData {
def main(args: Array[String]) {
//Spark conf
val conf = new SparkConf().setAppName("Distributed Machine Learning").setMaster("local[*]")
val sc = new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
//Turn off logs
val rootLogger = Logger.getRootLogger()
rootLogger.setLevel(Level.ERROR)
//Parse arguments
val parser = new PrepArgParser(args)
val dataset = parser.dataset()
var workingDir = parser.dir()
val numPartitions = parser.partitions()
val method = parser.method()
//Load data
val (train, test) = method match {
case "Classification" => Utils.loadAbsolutLibSVMBinaryClassification(dataset, numPartitions, sc)
case "Regression" => Utils.loadAbsolutLibSVMRegression(dataset, numPartitions, sc)
case _ => throw new IllegalArgumentException("The method " + method + " is not supported.")
}
// append "/" to workingDir if necessary
workingDir = workingDir + ( if (workingDir.takeRight(1) != "/") "/" else "" )
val trainPath: Path = Path.fromString(workingDir + "train")
Try(trainPath.deleteRecursively(continueOnFailure = false))
val testPath: Path = Path.fromString(workingDir + "test")
Try(testPath.deleteRecursively(continueOnFailure = false))
MLUtils.saveAsLibSVMFile(train, workingDir + "train")
MLUtils.saveAsLibSVMFile(test, workingDir + "test")
}
}
示例7: Helper
//设置package包名称以及导入依赖的类
import org.apache.log4j.Logger
import org.apache.log4j.Level
import scala.collection.mutable.HashMap
object Helper {
Logger.getLogger("org.apache.spark").setLevel(Level.WARN)
Logger
.getLogger("org.apache.spark.storage.BlockManager")
.setLevel(Level.ERROR)
def configureTwitterCredentials(apiKey: String,
apiSecret: String,
accessToken: String,
accessTokenSecret: String) {
val configs = Map(
"apiKey" -> apiKey,
"apiSecret" -> apiSecret,
"accessToken" -> accessToken,
"accessTokenSecret" -> accessTokenSecret
)
println("Configuring Twitter OAuth")
configs.foreach {
case (key, value) =>
if (value.trim.isEmpty) {
throw new Exception(
"Error setting authentication - value for " + key + " not set -> value is " + value)
}
val fullKey = "twitter4j.oauth." + key.replace("api", "consumer")
System.setProperty(fullKey, value.trim)
println("\tProperty " + fullKey + " set as [" + value.trim + "]")
}
println()
}
}
示例8: JobRunner
//设置package包名称以及导入依赖的类
package org.wikimedia.research.recommendation.job.translation
import java.io.File
import java.text.SimpleDateFormat
import java.util.Calendar
import org.apache.log4j.{Level, LogManager, Logger}
import org.apache.spark.sql._
import scala.collection.parallel.ForkJoinTaskSupport
import scala.concurrent.forkjoin.ForkJoinPool
object JobRunner {
val log: Logger = LogManager.getLogger(JobRunner.getClass)
val SITE_PARALLELISM = 8
def main(args: Array[String]): Unit = {
log.info("Starting")
val params = ArgParser.parseArgs(args)
var sparkBuilder = SparkSession
.builder()
.appName("TranslationRecommendations")
if (params.runLocally) {
sparkBuilder = sparkBuilder.master("local[*]")
}
val spark = sparkBuilder.getOrCreate()
Logger.getLogger("org").setLevel(Level.WARN)
Logger.getLogger("org.wikimedia").setLevel(Level.INFO)
val timestamp = new SimpleDateFormat("yyyy-MM-dd-HHmmss").format(Calendar.getInstance.getTime)
log.info("Timestamp for creating files: " + timestamp)
if (params.scoreItems) {
val modelsInputDir = params.modelsDir.getOrElse(modelsOutputDir.get)
val predictionsOutputDir = params.outputDir.map(o => new File(o, timestamp + "_predictions"))
predictionsOutputDir.foreach(o => o.mkdir())
ScorePredictor.predictScores(spark, modelsInputDir, predictionsOutputDir, modelSites, featureData)
}
spark.stop()
log.info("Finished")
}
}
示例9: BorderFlowClustering
//设置package包名称以及导入依赖的类
package net.sansa_stack.examples.spark.ml.clustering
import scala.collection.mutable
import org.apache.spark.sql.SparkSession
import org.apache.log4j.{ Level, Logger }
import net.sansa_stack.ml.spark.clustering.BorderFlow
object BorderFlowClustering {
def main(args: Array[String]) = {
if (args.length < 1) {
System.err.println(
"Usage: BorderFlow <input> ")
System.exit(1)
}
val input = args(0) //"src/main/resources/BorderFlow_Sample1.txt"
val optionsList = args.drop(1).map { arg =>
arg.dropWhile(_ == '-').split('=') match {
case Array(opt, v) => (opt -> v)
case _ => throw new IllegalArgumentException("Invalid argument: " + arg)
}
}
val options = mutable.Map(optionsList: _*)
options.foreach {
case (opt, _) => throw new IllegalArgumentException("Invalid option: " + opt)
}
println("============================================")
println("| Border Flow example |")
println("============================================")
val spark = SparkSession.builder
.master("local[*]")
.appName(" BorderFlow example (" + input + ")")
.getOrCreate()
Logger.getRootLogger.setLevel(Level.ERROR)
BorderFlow(spark, input)
spark.stop
}
}
示例10: RDFGraphPIClustering
//设置package包名称以及导入依赖的类
package net.sansa_stack.examples.spark.ml.clustering
import scala.collection.mutable
import org.apache.spark.sql.SparkSession
import org.apache.log4j.{ Level, Logger }
import org.apache.spark.graphx.GraphLoader
import net.sansa_stack.ml.spark.clustering.{ RDFGraphPICClustering => RDFGraphPICClusteringAlg }
object RDFGraphPIClustering {
def main(args: Array[String]) = {
if (args.length < 3) {
System.err.println(
"Usage: RDFGraphPIClustering <input> <k> <numIterations>")
System.exit(1)
}
val input = args(0) //"src/main/resources/BorderFlow_Sample1.txt"
val k = args(1).toInt
val numIterations = args(2).toInt
val optionsList = args.drop(3).map { arg =>
arg.dropWhile(_ == '-').split('=') match {
case Array(opt, v) => (opt -> v)
case _ => throw new IllegalArgumentException("Invalid argument: " + arg)
}
}
val options = mutable.Map(optionsList: _*)
options.foreach {
case (opt, _) => throw new IllegalArgumentException("Invalid option: " + opt)
}
println("============================================")
println("| Power Iteration Clustering example |")
println("============================================")
val sparkSession = SparkSession.builder
.master("local[*]")
.appName(" Power Iteration Clustering example (" + input + ")")
.getOrCreate()
Logger.getRootLogger.setLevel(Level.ERROR)
// Load the graph
val graph = GraphLoader.edgeListFile(sparkSession.sparkContext, input)
val model = RDFGraphPICClusteringAlg(sparkSession, graph, k, numIterations).run()
val clusters = model.assignments.collect().groupBy(_.cluster).mapValues(_.map(_.id))
val assignments = clusters.toList.sortBy { case (k, v) => v.length }
val assignmentsStr = assignments
.map {
case (k, v) =>
s"$k -> ${v.sorted.mkString("[", ",", "]")}"
}.mkString(",")
val sizesStr = assignments.map {
_._2.size
}.sorted.mkString("(", ",", ")")
println(s"Cluster assignments: $assignmentsStr\ncluster sizes: $sizesStr")
sparkSession.stop
}
}
示例11: RDFByModularityClustering
//设置package包名称以及导入依赖的类
package net.sansa_stack.examples.spark.ml.clustering
import scala.collection.mutable
import org.apache.spark.sql.SparkSession
import org.apache.log4j.{ Level, Logger }
import net.sansa_stack.ml.spark.clustering.{ RDFByModularityClustering => RDFByModularityClusteringAlg }
object RDFByModularityClustering {
def main(args: Array[String]) = {
if (args.length < 3) {
System.err.println(
"Usage: RDFByModularityClustering <input> <output> <numIterations>")
System.exit(1)
}
val graphFile = args(0) //"src/main/resources/Clustering_sampledata.nt",
val outputFile = args(1)
val numIterations = args(2).toInt
val optionsList = args.drop(3).map { arg =>
arg.dropWhile(_ == '-').split('=') match {
case Array(opt, v) => (opt -> v)
case _ => throw new IllegalArgumentException("Invalid argument: " + arg)
}
}
val options = mutable.Map(optionsList: _*)
options.foreach {
case (opt, _) => throw new IllegalArgumentException("Invalid option: " + opt)
}
println("============================================")
println("| RDF By Modularity Clustering example |")
println("============================================")
val sparkSession = SparkSession.builder
.master("local[*]")
.appName(" RDF By Modularity Clustering example (" + graphFile + ")")
.getOrCreate()
Logger.getRootLogger.setLevel(Level.ERROR)
RDFByModularityClusteringAlg(sparkSession.sparkContext, numIterations, graphFile, outputFile)
sparkSession.stop
}
}
示例12: MyLog1
//设置package包名称以及导入依赖的类
package com.chapter14.Serilazition
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.log4j.LogManager
import org.apache.log4j.Level
import org.apache.log4j.Logger
object MyLog1 extends Serializable {
def main(args: Array[String]):Unit= {
// Stting logger level as WARN
val log = LogManager.getRootLogger
log.setLevel(Level.WARN)
@transient lazy val log2 = org.apache.log4j.LogManager.getLogger("myLogger")
// Creating Spark Context
val conf = new SparkConf().setAppName("My App").setMaster("local[*]")
val sc = new SparkContext(conf)
//Started the computation and printing the logging inforamtion
//log.warn("Started")
//val i = 0
val data = sc.parallelize(0 to 100000)
data.foreach(i => log.info("My number"+ i))
data.collect()
log.warn("Finished")
}
}
示例13: MyMapper
//设置package包名称以及导入依赖的类
package com.chapter14.Serilazition
import org.apache.log4j.{Level, LogManager, PropertyConfigurator}
import org.apache.spark._
import org.apache.spark.rdd.RDD
class MyMapper(n: Int) extends Serializable{
@transient lazy val log = org.apache.log4j.LogManager.getLogger("myLogger")
def MyMapperDosomething(rdd: RDD[Int]): RDD[String] =
rdd.map{ i =>
log.warn("mapping: " + i)
(i + n).toString
}
}
//Companion object
object MyMapper {
def apply(n: Int): MyMapper = new MyMapper(n)
}
//Main object
object MyLog {
def main(args: Array[String]) {
val log = LogManager.getRootLogger
log.setLevel(Level.WARN)
val conf = new SparkConf()
.setAppName("My App")
.setMaster("local[*]")
conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
val sc = new SparkContext(conf)
log.warn("Started")
val data = sc.parallelize(1 to 100000)
val mapper = MyMapper(1)
val other = mapper.MyMapperDosomething(data)
other.collect()
log.warn("Finished")
}
}
开发者ID:PacktPublishing,项目名称:Scala-and-Spark-for-Big-Data-Analytics,代码行数:40,代码来源:MyLogCompleteDemo.scala
示例14: MyMapper2
//设置package包名称以及导入依赖的类
package com.chapter14.Serilazition
import org.apache.log4j.{ Level, LogManager, PropertyConfigurator }
import org.apache.spark._
import org.apache.spark.rdd.RDD
class MyMapper2(n: Int) {
@transient lazy val log = org.apache.log4j.LogManager.getLogger("myLogger")
def MyMapperDosomething(rdd: RDD[Int]): RDD[String] =
rdd.map { i =>
log.warn("mapping: " + i)
(i + n).toString
}
}
//Companion object
object MyMapper2 {
def apply(n: Int): MyMapper = new MyMapper(n)
}
//Main object
object KyroRegistrationDemo {
def main(args: Array[String]) {
val log = LogManager.getRootLogger
log.setLevel(Level.WARN)
val conf = new SparkConf()
.setAppName("My App")
.setMaster("local[*]")
conf.registerKryoClasses(Array(classOf[MyMapper2]))
conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
val sc = new SparkContext(conf)
log.warn("Started")
val data = sc.parallelize(1 to 100000)
val mapper = MyMapper2(10)
val other = mapper.MyMapperDosomething(data)
other.collect()
log.warn("Finished")
}
}
开发者ID:PacktPublishing,项目名称:Scala-and-Spark-for-Big-Data-Analytics,代码行数:41,代码来源:KyroRegistrationDemo.scala
示例15: MyMapper
//设置package包名称以及导入依赖的类
package com.chapter16.SparkTesting
import org.apache.log4j.{ Level, LogManager }
import org.apache.spark._
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SparkSession
class MyMapper(n: Int) extends Serializable {
@transient lazy val log = org.apache.log4j.LogManager.getLogger("myLogger")
def logMapper(rdd: RDD[Int]): RDD[String] =
rdd.map { i =>
log.warn("mapping: " + i)
(i + n).toString
}
}
//Companion object
object MyMapper {
def apply(n: Int): MyMapper = new MyMapper(n)
}
//Main object
object myCustomLogwithClosureSerializable {
def main(args: Array[String]) {
val log = LogManager.getRootLogger
log.setLevel(Level.WARN)
val spark = SparkSession
.builder
.master("local[*]")
.config("spark.sql.warehouse.dir", "E:/Exp/")
.appName("Testing")
.getOrCreate()
log.warn("Started")
val data = spark.sparkContext.parallelize(1 to 100000)
val mapper = MyMapper(1)
val other = mapper.logMapper(data)
other.collect()
log.warn("Finished")
}
}
开发者ID:PacktPublishing,项目名称:Scala-and-Spark-for-Big-Data-Analytics,代码行数:41,代码来源:myCustomLogwithClosureSerializable.scala