Skip to content

automatic log method's parameters and result information with scalameta

Notifications You must be signed in to change notification settings

LoranceChen/meta-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Meta Logger

logging method's calling stack even in multiple threads.

Dependency

Usage

SBT config

scalacOptions += "-Xplugin-require:macroparadise"
resolvers += Resolver.bintrayIvyRepo("scalameta", "maven")
addCompilerPlugin("org.scalameta" % "paradise" % "3.0.0-M9" cross CrossVersion.full)

libraryDependencies += "com.scalachan" % "meta-logger_2.12" % "0.1"

add annotation to your code

import lorance.metalog._

object Main extends App with MetaLogger {
	NeedLog.something
}

object NeedLog {

	@Log(Info() :: Nil, printLogger)
	def something() {
		"hello world"
	}
}

How does it works

meta annotation @Log/@LogFutureaffect a method at compile pre-process time:

//before
@Log(Info() :: Nil, printLogger)
def add1(x: Int) = {
	x + 1
}
//after parsed, ===> simple as:
def add1(x: Int)(implicit metaLogContext: LogContext) = {
	println(s"current time - metaLogContext.logId.id - ... param: ${x}")
	val result = { x + 1 }
	println(s"current time - metaLogContext.logId.id - ... result: ${result}")
	result
}

TODO

  • add a @VirtualLog for trait def (seems some bug in scalameta at this point)

About

automatic log method's parameters and result information with scalameta

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages