You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2017/05/02 01:56:52 UTC
Timing tasks
Hi All:
I find myself writing a lot of methods like:
LOGGER.debug("Doing things with {}", foo);
final StopWatch watch = StopWatch.createStarted();
// Do this
// Do that
// And then some
watch.stop();
LOGGER.debug("Did foo things in {}", watch);
Where the stop watch is Apache Commons Lang's
https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/time/StopWatch.html
Any thoughts on making things less verbose?
Making watch.stop() return "this" would save a line but I'd have to clone
StopWatch to do that which I do not mind.
Gary
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: Timing tasks
Posted by Gary Gregory <ga...@gmail.com>.
As parallel thought, I was thinking about adding timings on traceExit calls
by creating a new Flow message factory (since you do not want to pay the
price of calling System.nanos unless you want to.)
The nanos would be tracked in a new class, SimpleEntryTimestampMessage
(instead of SimpleEntryMessage).
This has has the benefit of not growing the public Logger API. You just
need to create your Logger with the right factory.
For the more general case aside from traceEnter/traceExit, I'm not sure how
to do that.
The nice thing about traceEnter is that it returns an object. All other
Logger APIs return null.
Gary
On Mon, May 1, 2017 at 7:00 PM, Matt Sicker <bo...@gmail.com> wrote:
> That use case reminds me a bit of Zipkin/Brave, though that's more so for
> tracing between services than for local timing. I'm kind of wondering what
> kind of log4j api you could make from this, though.
>
> On 1 May 2017 at 20:56, Gary Gregory <ga...@gmail.com> wrote:
>
> > Hi All:
> >
> > I find myself writing a lot of methods like:
> >
> > LOGGER.debug("Doing things with {}", foo);
> > final StopWatch watch = StopWatch.createStarted();
> > // Do this
> > // Do that
> > // And then some
> > watch.stop();
> > LOGGER.debug("Did foo things in {}", watch);
> >
> > Where the stop watch is Apache Commons Lang's
> > https://commons.apache.org/proper/commons-lang/apidocs/
> > org/apache/commons/lang3/time/StopWatch.html
> >
> > Any thoughts on making things less verbose?
> >
> > Making watch.stop() return "this" would save a line but I'd have to clone
> > StopWatch to do that which I do not mind.
> >
> > Gary
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> > linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
> >
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> > 1617290459>
> > JUnit in Action, Second Edition
> > <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> > linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
> 18%22
> > >
> >
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> > 1935182021>
> > Spring Batch in Action
> > <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> > linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> > 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> > 1935182951>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: Timing tasks
Posted by Matt Sicker <bo...@gmail.com>.
That use case reminds me a bit of Zipkin/Brave, though that's more so for
tracing between services than for local timing. I'm kind of wondering what
kind of log4j api you could make from this, though.
On 1 May 2017 at 20:56, Gary Gregory <ga...@gmail.com> wrote:
> Hi All:
>
> I find myself writing a lot of methods like:
>
> LOGGER.debug("Doing things with {}", foo);
> final StopWatch watch = StopWatch.createStarted();
> // Do this
> // Do that
> // And then some
> watch.stop();
> LOGGER.debug("Did foo things in {}", watch);
>
> Where the stop watch is Apache Commons Lang's
> https://commons.apache.org/proper/commons-lang/apidocs/
> org/apache/commons/lang3/time/StopWatch.html
>
> Any thoughts on making things less verbose?
>
> Making watch.stop() return "this" would save a line but I'd have to clone
> StopWatch to do that which I do not mind.
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22
> >
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
--
Matt Sicker <bo...@gmail.com>
Re: Timing tasks
Posted by Mikael Ståldal <mi...@magine.com>.
Removed duplicate Timer class.
On Tue, May 2, 2017 at 1:58 PM, Mikael Ståldal <mi...@magine.com>
wrote:
> Why is this class duplicated? Can't we remove the one in log4j-core?
>
> On Tue, May 2, 2017 at 4:59 AM, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
>> We have had this since I started log4j. It is in both core and api as
>> Timer.
>>
>> You can do
>>
>> Timer timer = new Timer(“Step1”);
>> ….
>> ….
>> timer.start()
>> …
>> …
>> …
>> timer.stop();
>> LOGGERr.debug(timer);
>>
>> I had a version of this at one time that automatically logged when stop
>> was called. That could easily be done by doing:
>>
>> Timer timer = new Timer(“Step 1”) {
>> public void stop() {
>> super();
>> LOGGER.debug(this);
>> }
>>
>> Or we could make another version that does this. It might make sense to
>> have start and stop also return this so you could do:
>>
>> Timer timer = new Timer(“Step 1).start();
>> ….
>> ….
>> Logger.debug(timer.stop());
>>
>> This change would be backwards compatible so we could do that without any
>> problem.
>>
>> Note that Timer also supports pause() and resume() if you want to
>> eliminate the time spent in called methods.
>>
>> Ralph
>>
>> > On May 1, 2017, at 6:56 PM, Gary Gregory <ga...@gmail.com>
>> wrote:
>> >
>> > Hi All:
>> >
>> > I find myself writing a lot of methods like:
>> >
>> > LOGGER.debug("Doing things with {}", foo);
>> > final StopWatch watch = StopWatch.createStarted();
>> > // Do this
>> > // Do that
>> > // And then some
>> > watch.stop();
>> > LOGGER.debug("Did foo things in {}", watch);
>> >
>> > Where the stop watch is Apache Commons Lang's
>> > https://commons.apache.org/proper/commons-lang/apidocs/org/
>> apache/commons/lang3/time/StopWatch.html
>> >
>> > Any thoughts on making things less verbose?
>> >
>> > Making watch.stop() return "this" would save a line but I'd have to
>> clone
>> > StopWatch to do that which I do not mind.
>> >
>> > Gary
>> >
>> > --
>> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> > Java Persistence with Hibernate, Second Edition
>> > <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
>> Code=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>> >
>> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1617290459>
>> > JUnit in Action, Second Edition
>> > <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
>> Code=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>> >
>> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1935182021>
>> > Spring Batch in Action
>> > <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
>> Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
>> nk_id%7D%7D%22%3ESpring+Batch+in+Action>
>> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1935182951>
>> > Blog: http://garygregory.wordpress.com
>> > Home: http://garygregory.com/
>> > Tweet! http://twitter.com/GaryGregory
>>
>>
>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3 | 114 46 Stockholm, Sweden | www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>
--
[image: MagineTV]
*Mikael Ståldal*
Senior software developer
*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3 | 114 46 Stockholm, Sweden | www.magine.com
Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.
Re: Timing tasks
Posted by Dominik Psenner <dp...@gmail.com>.
Maybe implement an AutoClosableTimer that implements the AutoClosable
interface [1]? I often take use of the using(something){} directive in C#
and find it quite readable.
[1] https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html
On 2 May 2017 1:59 p.m., "Mikael Ståldal" <mi...@magine.com> wrote:
> As far as I can see, the Timer class is in test only?
>
> On Tue, May 2, 2017 at 1:58 PM, Mikael Ståldal <mi...@magine.com>
> wrote:
>
> > Why is this class duplicated? Can't we remove the one in log4j-core?
> >
> > On Tue, May 2, 2017 at 4:59 AM, Ralph Goers <ra...@dslextreme.com>
> > wrote:
> >
> >> We have had this since I started log4j. It is in both core and api as
> >> Timer.
> >>
> >> You can do
> >>
> >> Timer timer = new Timer(“Step1”);
> >> ….
> >> ….
> >> timer.start()
> >> …
> >> …
> >> …
> >> timer.stop();
> >> LOGGERr.debug(timer);
> >>
> >> I had a version of this at one time that automatically logged when stop
> >> was called. That could easily be done by doing:
> >>
> >> Timer timer = new Timer(“Step 1”) {
> >> public void stop() {
> >> super();
> >> LOGGER.debug(this);
> >> }
> >>
> >> Or we could make another version that does this. It might make sense to
> >> have start and stop also return this so you could do:
> >>
> >> Timer timer = new Timer(“Step 1).start();
> >> ….
> >> ….
> >> Logger.debug(timer.stop());
> >>
> >> This change would be backwards compatible so we could do that without
> any
> >> problem.
> >>
> >> Note that Timer also supports pause() and resume() if you want to
> >> eliminate the time spent in called methods.
> >>
> >> Ralph
> >>
> >> > On May 1, 2017, at 6:56 PM, Gary Gregory <ga...@gmail.com>
> >> wrote:
> >> >
> >> > Hi All:
> >> >
> >> > I find myself writing a lot of methods like:
> >> >
> >> > LOGGER.debug("Doing things with {}", foo);
> >> > final StopWatch watch = StopWatch.createStarted();
> >> > // Do this
> >> > // Do that
> >> > // And then some
> >> > watch.stop();
> >> > LOGGER.debug("Did foo things in {}", watch);
> >> >
> >> > Where the stop watch is Apache Commons Lang's
> >> > https://commons.apache.org/proper/commons-lang/apidocs/org/
> >> apache/commons/lang3/time/StopWatch.html
> >> >
> >> > Any thoughts on making things less verbose?
> >> >
> >> > Making watch.stop() return "this" would save a line but I'd have to
> >> clone
> >> > StopWatch to do that which I do not mind.
> >> >
> >> > Gary
> >> >
> >> > --
> >> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >> > Java Persistence with Hibernate, Second Edition
> >> > <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
> >> ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
> >> Code=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
> >> >
> >> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> >> am2&o=1&a=1617290459>
> >> > JUnit in Action, Second Edition
> >> > <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
> >> ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
> >> Code=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
> >> >
> >> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> >> am2&o=1&a=1935182021>
> >> > Spring Batch in Action
> >> > <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
> >> ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
> >> Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
> >> nk_id%7D%7D%22%3ESpring+Batch+in+Action>
> >> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> >> am2&o=1&a=1935182951>
> >> > Blog: http://garygregory.wordpress.com
> >> > Home: http://garygregory.com/
> >> > Tweet! http://twitter.com/GaryGregory
> >>
> >>
> >>
> >
> >
> > --
> > [image: MagineTV]
> >
> > *Mikael Ståldal*
> > Senior software developer
> >
> > *Magine TV*
> > mikael.staldal@magine.com
> > Grev Turegatan 3 | 114 46 Stockholm, Sweden | www.magine.com
> >
> > Privileged and/or Confidential Information may be contained in this
> > message. If you are not the addressee indicated in this message
> > (or responsible for delivery of the message to such a person), you may
> not
> > copy or deliver this message to anyone. In such case,
> > you should destroy this message and kindly notify the sender by reply
> > email.
> >
>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3 | 114 46 Stockholm, Sweden | www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>
Re: Timing tasks
Posted by Mikael Ståldal <mi...@magine.com>.
As far as I can see, the Timer class is in test only?
On Tue, May 2, 2017 at 1:58 PM, Mikael Ståldal <mi...@magine.com>
wrote:
> Why is this class duplicated? Can't we remove the one in log4j-core?
>
> On Tue, May 2, 2017 at 4:59 AM, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
>> We have had this since I started log4j. It is in both core and api as
>> Timer.
>>
>> You can do
>>
>> Timer timer = new Timer(“Step1”);
>> ….
>> ….
>> timer.start()
>> …
>> …
>> …
>> timer.stop();
>> LOGGERr.debug(timer);
>>
>> I had a version of this at one time that automatically logged when stop
>> was called. That could easily be done by doing:
>>
>> Timer timer = new Timer(“Step 1”) {
>> public void stop() {
>> super();
>> LOGGER.debug(this);
>> }
>>
>> Or we could make another version that does this. It might make sense to
>> have start and stop also return this so you could do:
>>
>> Timer timer = new Timer(“Step 1).start();
>> ….
>> ….
>> Logger.debug(timer.stop());
>>
>> This change would be backwards compatible so we could do that without any
>> problem.
>>
>> Note that Timer also supports pause() and resume() if you want to
>> eliminate the time spent in called methods.
>>
>> Ralph
>>
>> > On May 1, 2017, at 6:56 PM, Gary Gregory <ga...@gmail.com>
>> wrote:
>> >
>> > Hi All:
>> >
>> > I find myself writing a lot of methods like:
>> >
>> > LOGGER.debug("Doing things with {}", foo);
>> > final StopWatch watch = StopWatch.createStarted();
>> > // Do this
>> > // Do that
>> > // And then some
>> > watch.stop();
>> > LOGGER.debug("Did foo things in {}", watch);
>> >
>> > Where the stop watch is Apache Commons Lang's
>> > https://commons.apache.org/proper/commons-lang/apidocs/org/
>> apache/commons/lang3/time/StopWatch.html
>> >
>> > Any thoughts on making things less verbose?
>> >
>> > Making watch.stop() return "this" would save a line but I'd have to
>> clone
>> > StopWatch to do that which I do not mind.
>> >
>> > Gary
>> >
>> > --
>> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> > Java Persistence with Hibernate, Second Edition
>> > <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&link
>> Code=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>> >
>> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1617290459>
>> > JUnit in Action, Second Edition
>> > <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&link
>> Code=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>> >
>> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1935182021>
>> > Spring Batch in Action
>> > <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?
>> ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&link
>> Code=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Bli
>> nk_id%7D%7D%22%3ESpring+Batch+in+Action>
>> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>> am2&o=1&a=1935182951>
>> > Blog: http://garygregory.wordpress.com
>> > Home: http://garygregory.com/
>> > Tweet! http://twitter.com/GaryGregory
>>
>>
>>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3 | 114 46 Stockholm, Sweden | www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.
>
--
[image: MagineTV]
*Mikael Ståldal*
Senior software developer
*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3 | 114 46 Stockholm, Sweden | www.magine.com
Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.
Re: Timing tasks
Posted by Mikael Ståldal <mi...@magine.com>.
Why is this class duplicated? Can't we remove the one in log4j-core?
On Tue, May 2, 2017 at 4:59 AM, Ralph Goers <ra...@dslextreme.com>
wrote:
> We have had this since I started log4j. It is in both core and api as
> Timer.
>
> You can do
>
> Timer timer = new Timer(“Step1”);
> ….
> ….
> timer.start()
> …
> …
> …
> timer.stop();
> LOGGERr.debug(timer);
>
> I had a version of this at one time that automatically logged when stop
> was called. That could easily be done by doing:
>
> Timer timer = new Timer(“Step 1”) {
> public void stop() {
> super();
> LOGGER.debug(this);
> }
>
> Or we could make another version that does this. It might make sense to
> have start and stop also return this so you could do:
>
> Timer timer = new Timer(“Step 1).start();
> ….
> ….
> Logger.debug(timer.stop());
>
> This change would be backwards compatible so we could do that without any
> problem.
>
> Note that Timer also supports pause() and resume() if you want to
> eliminate the time spent in called methods.
>
> Ralph
>
> > On May 1, 2017, at 6:56 PM, Gary Gregory <ga...@gmail.com> wrote:
> >
> > Hi All:
> >
> > I find myself writing a lot of methods like:
> >
> > LOGGER.debug("Doing things with {}", foo);
> > final StopWatch watch = StopWatch.createStarted();
> > // Do this
> > // Do that
> > // And then some
> > watch.stop();
> > LOGGER.debug("Did foo things in {}", watch);
> >
> > Where the stop watch is Apache Commons Lang's
> > https://commons.apache.org/proper/commons-lang/apidocs/
> org/apache/commons/lang3/time/StopWatch.html
> >
> > Any thoughts on making things less verbose?
> >
> > Making watch.stop() return "this" would save a line but I'd have to clone
> > StopWatch to do that which I do not mind.
> >
> > Gary
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
> >
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1617290459>
> > JUnit in Action, Second Edition
> > <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22
> >
> >
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182021>
> > Spring Batch in Action
> > <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> > <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182951>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
>
>
--
[image: MagineTV]
*Mikael Ståldal*
Senior software developer
*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3 | 114 46 Stockholm, Sweden | www.magine.com
Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.
Re: Timing tasks
Posted by Ralph Goers <ra...@dslextreme.com>.
We have had this since I started log4j. It is in both core and api as Timer.
You can do
Timer timer = new Timer(“Step1”);
….
….
timer.start()
…
…
…
timer.stop();
LOGGERr.debug(timer);
I had a version of this at one time that automatically logged when stop was called. That could easily be done by doing:
Timer timer = new Timer(“Step 1”) {
public void stop() {
super();
LOGGER.debug(this);
}
Or we could make another version that does this. It might make sense to have start and stop also return this so you could do:
Timer timer = new Timer(“Step 1).start();
….
….
Logger.debug(timer.stop());
This change would be backwards compatible so we could do that without any problem.
Note that Timer also supports pause() and resume() if you want to eliminate the time spent in called methods.
Ralph
> On May 1, 2017, at 6:56 PM, Gary Gregory <ga...@gmail.com> wrote:
>
> Hi All:
>
> I find myself writing a lot of methods like:
>
> LOGGER.debug("Doing things with {}", foo);
> final StopWatch watch = StopWatch.createStarted();
> // Do this
> // Do that
> // And then some
> watch.stop();
> LOGGER.debug("Did foo things in {}", watch);
>
> Where the stop watch is Apache Commons Lang's
> https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/time/StopWatch.html
>
> Any thoughts on making things less verbose?
>
> Making watch.stop() return "this" would save a line but I'd have to clone
> StopWatch to do that which I do not mind.
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory