2 * Copyright 2011-2012 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
36 package gr.grnet.aquarium.util
38 import date.TimeHelpers
39 import org.slf4j.Logger
43 * @author Christos KK Loverdos <loverdos@gmail.com>
47 def logStarting(logger: Logger): Unit = {
48 logger.debug("Starting ...")
51 def logStarting(logger: Logger, fmt: String, args: Any*): Unit = {
52 logger.debug("Starting %s ...".format(fmt.format(args: _*)))
55 def logStarted(logger: Logger, ms0: Long, ms1: Long): Unit = {
56 logger.info("Started in %.3f sec".format(TimeHelpers.secDiffOfMillis(ms0, ms1)))
59 def logStarted(logger: Logger, ms0: Long, ms1: Long, fmt: String, args: Any*): Unit = {
60 logger.info("Started %s in %.3f sec".format(fmt.format(args: _*), TimeHelpers.secDiffOfMillis(ms0, ms1)))
63 def logStopping(logger: Logger): Unit = {
64 logger.debug("Stopping ...")
67 def logStopping(logger: Logger, fmt: String, args: Any*): Unit = {
68 logger.debug("Stopping %s ...".format(fmt.format(args: _*)))
71 def logStopped(logger: Logger, ms0: Long, ms1: Long): Unit = {
72 logger.info("Stopped in %.3f sec".format(TimeHelpers.secDiffOfMillis(ms0, ms1)))
75 def logStopped(logger: Logger, ms0: Long, ms1: Long, fmt: String, args: Any*): Unit = {
76 logger.info("Stopped %s in %.3f sec".format(fmt.format(args: _*), TimeHelpers.secDiffOfMillis(ms0, ms1)))
79 def logChainOfCauses(logger: Logger, t: Throwable, message: String = "Oops!"): Unit = {
80 logger.error(message + "\n{}", chainOfCausesForLogging(t))
83 def logChainOfCausesAndException(logger: Logger, t: Throwable, message: String = "Oops!"): Unit = {
84 logger.error(message + "\n{}", chainOfCausesForLogging(t))
85 logger.error(message, t)
89 final def Debug(logger: Logger, fmt: String, args: Any*): Unit = {
90 if(logger.isDebugEnabled) {
91 logger.debug(fmt.format(args:_*))
96 final def Info(logger: Logger, fmt: String, args: Any*): Unit = {
97 if(logger.isInfoEnabled) {
98 logger.info(fmt.format(args:_*))
103 final def Warn(logger: Logger, fmt: String, args: Any*): Unit = {
104 if(logger.isWarnEnabled) {
105 logger.warn(fmt.format(args:_*))
110 final def Error(logger: Logger, fmt: String, args: Any*): Unit = {
111 if(logger.isErrorEnabled) {
112 logger.error(fmt.format(args:_*))
117 final def Error(logger: Logger, t: Throwable, fmt: String, args: Any*): Unit = {
118 if(logger.isErrorEnabled) {
119 logger.error(fmt.format(args:_*), t)
123 final def DebugMap[K, V](
126 map: scala.collection.Map[K, V],
127 oneLineLimit: Int = 3
130 if(logger.isDebugEnabled) {
131 val mapSize = map.size
132 if(mapSize <= oneLineLimit) {
133 Debug(logger, "%s [#=%s] = %s", name, mapSize, map)
135 logger.debug("%s [#=%s]:", name, mapSize)
136 val maxKeySize = maxStringSize(map.keySet)
138 this.Debug(logger, "%s -> %s", rpad(k.toString, maxKeySize), v)
144 final def DebugSeq[T](logger: Logger, name: String, seq: scala.collection.Seq[T], oneLineLimit: Int = 3): Unit = {
145 if(logger.isDebugEnabled) {
146 val seqSize = seq.size
147 if(seqSize <= oneLineLimit) {
148 Debug(logger, "%s [#=%s] = %s", name, seqSize, seq)
150 Debug(logger, "%s [#=%s]: ", name, seqSize)
151 seq.foreach(Debug(logger, "%s", _))
156 final def DebugSet[T](logger: Logger, name: String, set: scala.collection.Set[T], oneLineLimit: Int = 3): Unit = {
157 if(logger.isDebugEnabled) {
158 val setSize = set.size
159 if(setSize <= oneLineLimit) {
160 Debug(logger, "%s [#=%s] = %s", name, setSize, set)
162 Debug(logger, "%s [#=%s]: ", name, setSize)
163 set.foreach(Debug(logger, "%s", _))