Files
golib/logger
Nicolas JUHEL 61a73ba606 Package Certificates:
- fix bug with cert type marshall/unmarshall
- add old config to allow retro compatibility
- add new type function to retrieve a tls root ca cert instead of a slice of string to get root ca

Package HTTPCli:
- fix default DNS Mapper
- optimze global DNS Mapper
- fix non closing sub goroutine

Package HTTPCli/DNS-Mapper:
- change request function of Root CA with function of root ca cert instance
- add function to return a root ca cert from a function that return a slice of root ca string

Package Config/Components:
- httpcli: bump sub package of certificate, httpcli
- httpcli: adjust code following bump
- httpcli: change request function of Root CA with function of root ca cert instance
- httpcli: add function to return a root ca cert from a function that return a slice of root ca string
- tls: change request function of Root CA with function of root ca cert instance
- tls: add function to return a root ca cert from a function that return a slice of root ca string

Package IOUtils/mapCloser:
- fix bug with mapcloser not stopped
- optimize code & goroutine

Package Logger:
- rework mapCloser call
- optimize mapClaoser managment

Package Request:
- rework error managment
- using []byte instead of buffer to read response body
- add free capability
- optimize memory consumption

Package Socket / Server:
- add filtering error capability
- add params to specify a function called on each new connection and before using the connection
- the new function param allow to update the network incomming connection (like buffer, deadline...)
- rework some useless atomic to direct value to optimize code

Package Socket/Delim:
- rework to optimize memory & variable use
- remove capabilities of update the instance when running, prefert recreate new one if necessary

Other:
- bump dependencies
- minor bug / fix
2025-01-14 15:01:54 +01:00
..
2024-09-04 10:35:18 +02:00
2024-02-28 13:41:33 +01:00
2024-02-28 13:41:33 +01:00
2023-06-26 08:36:29 +02:00
2023-12-14 13:49:14 +01:00
2024-09-04 09:55:17 +02:00
2023-06-26 08:36:29 +02:00
2023-06-26 08:36:29 +02:00
2024-02-28 13:41:33 +01:00
2023-06-26 08:36:29 +02:00
2023-06-26 08:36:29 +02:00
2023-06-26 08:36:29 +02:00
2023-10-15 17:55:04 +02:00
2025-01-14 15:01:54 +01:00
2025-01-14 15:01:54 +01:00
2023-07-26 21:11:39 +02:00
2025-01-14 15:01:54 +01:00
2023-06-26 08:36:29 +02:00
2021-05-26 11:04:33 +02:00
2023-06-26 08:36:29 +02:00

Logger pakcage

Help manage logger. This package does not implement a logger but user logrus as logger behind. This package will simplify call of logger and allow more features like *log.Logger wrapper.

Exmaple of implement

In your file, first add the import of golib/logger :

	import liblog "github.com/nabbar/golib/logger"

Initialize the logger like this

	log := liblog.New()
	log.SetLevel(liblog.InfoLevel)

	if err := l.SetOptions(context.TODO(), &liblog.Options{
		DisableStandard:  false,
		DisableStack:     false,
		DisableTimestamp: false,
		EnableTrace:      false,
		TraceFilter:      "",
		DisableColor:     false,
		LogFile: []liblog.OptionsFile{
			{
				LogLevel: []string{
					"panic",
					"fatal",
					"error",
					"warning",
					"info",
					"debug",
				},
				Filepath:         "/path/to/my/logfile-with-trace",
				Create:           true,
				CreatePath:       true,
				FileMode:         0644,
				PathMode:         0755,
				DisableStack:     false,
				DisableTimestamp: false,
				EnableTrace:      true,
			},
		},
	}); err != nil {
		panic(err)
	}

Calling log like this :

	log.Info("Example log", nil, nil)
    
	// example with a struct name o that you want to expose in log
	// and an list of error : err1, err2 and err3
	log.LogDetails(liblog.InfoLevel, "example of detail log message with simple call", o, []error{err1, err2, err3}, nil, nil)
    

Having new log based on last logger but with some pre-defined information

    l := log.Clone(context.TODO())    
    l.SetFields(l.GetFields().Add("one-key", "one-value").Add("lib", "myLib").Add("pkg", "some-package"))
    l.Info("Example log with pre-define information", nil, nil)
    // will print line like : level=info fields.level=Info fields.time="2021-05-25T13:10:02.8033944+02:00" lib=myLib message="Example log with pre-define information" pkg=some-package stack=924 one-key=one-value
    
    // Override the field value on one log like this 
    l.LogDetails(liblog.InfoLevel, "example of detail log message with simple call", o, []error{err1, err2, err3}, liblog.NewFields().Add("lib", "another lib"), nil)
    // will print line like : level=info fields.level=Info fields.time="2021-05-25T13:10:02.8033944+02:00" lib="another lib" message="Example log with pre-define information" pkg=some-package stack=924 one-key=one-value

Implement other logger to this logger

Plug the SPF13 (Cobra / Viper) logger to this logger like this

   log.SetSPF13Level(liblog.InfoLevel, logSpf13)

Plug the Hashicorp logger hclog with the logger like this

   log.SetHashicorpHCLog()

Or get a hclog logger from the current logger like this

   hlog := log.NewHashicorpHCLog()

This call, return a go *log.Logger interface

   l := log.Clone(context.TODO())
   l.SetFields(l.GetFields().Add("one-key", "one-value").Add("lib", "myLib").Add("pkg", "some-package"))
   glog := l.GetStdLogger(liblog.ErrorLevel, log.LstdFlags|log.Lmicroseconds)

This call, will connect the default go *log.Logger

   log.SetStdLogger(liblog.ErrorLevel, log.LstdFlags|log.Lmicroseconds)