func (b *MemoryBackend) Log(level Level, calldepth int, rec *Record) error {
	var size int32
	n := &node{Record: rec}
	np := unsafe.Pointer(n)
	for {
		tailp := b.tail
		swapped := atomic.CompareAndSwapPointer(
			&b.tail,
			tailp,
			np,
		)
		if swapped == true {
			if tailp == nil {
				b.head = np
			} else {
				(*node)(tailp).next = n
			}
			size = atomic.AddInt32(&b.size, 1)
			break
		}
	}
	if b.maxSize > 0 && size > b.maxSize {
		for {
			headp := b.head
			head := (*node)(b.head)
			if head.next == nil {
				break
			}
			swapped := atomic.CompareAndSwapPointer(
				&b.head,
				headp,
				unsafe.Pointer(head.next),
			)
			if swapped == true {
				atomic.AddInt32(&b.size, -1)
				break
			}
		}
	}
	return nil
}
Log implements the Log method required by Backend.
package logging
import (
	"sync"
	"sync/atomic"
	"time"
	"unsafe"
)
func InitForTesting(level Level) *MemoryBackend {
	Reset()
	memoryBackend := NewMemoryBackend(10240)
	leveledBackend := AddModuleLevel(memoryBackend)
	leveledBackend.SetLevel(level, "")
	SetBackend(leveledBackend)
	timeNow = func() time.Time {
		return time.Unix(0, 0).UTC()
	}
	return memoryBackend
}
type node struct {
	next   *node
	Record *Record
}
func (n *node) Next() *node {
	return n.next
}
type MemoryBackend struct {
	size       int32
	maxSize    int32
	head, tail unsafe.Pointer
}
func NewMemoryBackend(size int) *MemoryBackend {
	return &MemoryBackend{maxSize: int32(size)}
}