github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekalog/init.go (about)

     1  // Copyright © 20202-2021. All rights reserved.
     2  // Author: Ilya Stroy.
     3  // Contacts: iyuryevich@pm.me, https://github.com/qioalice
     4  // License: https://opensource.org/licenses/MIT
     5  
     6  package ekalog
     7  
     8  import (
     9  	"os"
    10  )
    11  
    12  func init() {
    13  	entryPool.New = allocEntry
    14  
    15  	defaultConsoleEncoder = new(CI_ConsoleEncoder).doBuild()
    16  	defaultJSONEncoder = new(CI_JSONEncoder).doBuild()
    17  
    18  	_ = defaultConsoleEncoder
    19  	_ = defaultJSONEncoder
    20  
    21  	integrator := new(CommonIntegrator).
    22  		WithEncoder(defaultConsoleEncoder).
    23  		WithMinLevel(LEVEL_DEBUG).
    24  		WithMinLevelForStackTrace(LEVEL_WARNING).
    25  		WriteTo(os.Stdout)
    26  	integrator.build()
    27  
    28  	entry := acquireEntry()
    29  
    30  	baseLogger = new(Logger).setIntegrator(integrator).setEntry(entry)
    31  
    32  	// We know that nopLogger's fields won't be accessed, but we need them
    33  	// to pass Logger.assert() and Logger.IsValid() checks.
    34  	//
    35  	// So, (*CommonIntegrator)(nil) assigned to Integrator's type field
    36  	// won't be nil in Golang terms (it has a type no matter value still is nil),
    37  	// and we don't need a fully initialization of Entry - we won't use it.
    38  	// Logger.setIntegrator(), Logger.setEntry() doesn't have any checks.
    39  
    40  	nopLogger = new(Logger).setIntegrator((*CommonIntegrator)(nil)).setEntry(new(Entry))
    41  }