Skip to content
Snippets Groups Projects
Select Git revision
  • 6b7c5e1db5f86b9764155607f03f76efdb2e703c
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

connect.go

Blame
  • logLevel.go 2.34 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2022 xx foundation                                             //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file.                                                              //
    ////////////////////////////////////////////////////////////////////////////////
    
    //go:build js && wasm
    
    package logging
    
    import (
    	"fmt"
    	"github.com/pkg/errors"
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/xxdk-wasm/utils"
    	"log"
    	"syscall/js"
    )
    
    // LogLevel sets level of logging. All logs at the set level and below will be
    // displayed (e.g., when log level is ERROR, only ERROR, CRITICAL, and FATAL
    // messages will be printed).
    //
    // The default log level without updates is INFO.
    func LogLevel(threshold jww.Threshold) error {
    	if threshold < jww.LevelTrace || threshold > jww.LevelFatal {
    		return errors.Errorf("log level is not valid: log level: %d", threshold)
    	}
    
    	jww.SetLogThreshold(threshold)
    	jww.SetFlags(log.LstdFlags | log.Lmicroseconds)
    
    	ll := NewJsConsoleLogListener(threshold)
    	AddLogListener(ll.Listen)
    	jww.SetStdoutThreshold(jww.LevelFatal + 1)
    
    	msg := fmt.Sprintf("Log level set to: %s", threshold)
    	switch threshold {
    	case jww.LevelTrace:
    		fallthrough
    	case jww.LevelDebug:
    		fallthrough
    	case jww.LevelInfo:
    		jww.INFO.Print(msg)
    	case jww.LevelWarn:
    		jww.WARN.Print(msg)
    	case jww.LevelError:
    		jww.ERROR.Print(msg)
    	case jww.LevelCritical:
    		jww.CRITICAL.Print(msg)
    	case jww.LevelFatal:
    		jww.FATAL.Print(msg)
    	}
    
    	return nil
    }
    
    // LogLevelJS sets level of logging. All logs at the set level and below will be
    // displayed (e.g., when log level is ERROR, only ERROR, CRITICAL, and FATAL
    // messages will be printed).
    //
    // Log level options:
    //
    //	TRACE    - 0
    //	DEBUG    - 1
    //	INFO     - 2
    //	WARN     - 3
    //	ERROR    - 4
    //	CRITICAL - 5
    //	FATAL    - 6
    //
    // The default log level without updates is INFO.
    //
    // Parameters:
    //   - args[0] - Log level (int).
    //
    // Returns:
    //   - Throws TypeError if the log level is invalid.
    func LogLevelJS(_ js.Value, args []js.Value) any {
    	threshold := jww.Threshold(args[0].Int())
    	err := LogLevel(threshold)
    	if err != nil {
    		utils.Throw(utils.TypeError, err)
    		return nil
    	}
    
    	return nil
    }