1 // Copyright © 2016 Steve Francia <spf@spf13.com>.
3 // Use of this source code is governed by an MIT-style
4 // license that can be found in the LICENSE file.
6 package jwalterweatherman
12 type logCounter struct {
16 func (c *logCounter) incr() {
17 atomic.AddUint64(&c.counter, 1)
20 func (c *logCounter) resetCounter() {
21 atomic.StoreUint64(&c.counter, 0)
24 func (c *logCounter) getCount() uint64 {
25 return atomic.LoadUint64(&c.counter)
28 func (c *logCounter) Write(p []byte) (n int, err error) {
33 // LogCountForLevel returns the number of log invocations for a given threshold.
34 func (n *Notepad) LogCountForLevel(l Threshold) uint64 {
35 return n.logCounters[l].getCount()
38 // LogCountForLevelsGreaterThanorEqualTo returns the number of log invocations
39 // greater than or equal to a given threshold.
40 func (n *Notepad) LogCountForLevelsGreaterThanorEqualTo(threshold Threshold) uint64 {
43 for i := int(threshold); i < len(n.logCounters); i++ {
44 cnt += n.LogCountForLevel(Threshold(i))
50 // ResetLogCounters resets the invocation counters for all levels.
51 func (n *Notepad) ResetLogCounters() {
52 for _, np := range n.logCounters {