Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
github.com/universeofmadness/logger
Simple logger for Golang application that allows creating custom handling methods as well as final format of the message.
Example of basic usage.
package main
import (
"github.com/UniverseOfMadness/logger"
"os"
"time"
)
func main() {
f := logger.NewBasicFormatter("MyApp", time.RFC3339)
h := logger.NewStringWriterHandler(os.Stdout)
h.UseFormatter(f)
l := logger.New(h)
l.SetLevel(logger.LevelInfo)
l.Info("app started at {now}", "now", time.Now().Format(time.RFC3339))
l.Infof("hello %s", "world")
}
There are two types of logging functions:
List of standard logging functions:
List of formatted logging functions:
List of handlers provided with package:
io.StringWriter
interface
and writes all incoming logs to it.bufferOverflow
as parameter which is max number of logs stored in the handler. Any log added above limit will cause an error.Package includes Handler
interface that can be used to create custom handlers for
logger. StringWriterHandler
can be used as example for implementation.
List of formatters provided with package:
SimpleWebServer | 2020-08-25T19:06:36+02:00 | INFO | server is listening on 17333 | port:17333
). Allows setting application name and format for log date time.Package includes Formatter
interface that can be used to create custom formatters for
logger. BasicFormatter
can be used as example for implementation.
Default clock used in Logger
is only a wrapper for built-in Golang time.*
.
If application that implements this package requires a special time adjustment then
interface Clock
can be used to create custom implementation for the clock.
By default, Logger requires checking if error actually occurred before sending it to logs.
ErrorWrappedLogger
can handle errors directly with nil
check. For example:
package main
import (
"github.com/UniverseOfMadness/logger"
"os"
"time"
)
func main() {
f := logger.NewBasicFormatter("MyApp", time.RFC3339)
h := logger.NewStringWriterHandler(os.Stdout)
h.UseFormatter(f)
l := logger.New(h)
err := DoSomethingThatWillFail()
// handling error log without wrapper
if err != nil {
l.Error(err.Error())
}
wr := logger.NewErrorWrappedLogger(l)
// handling error log with wrapper
wr.OnError(err)
// additionally there is a possibility to wrap error with message
wr.OnErrorWrapped(err, "something went wrong in %s func: %w", "main")
}
nil
.fmt.Errorf
to Logger if error is not nil
.OnError
but passes message to Critical
instead of Error
.OnErrorWrapped
but passes message to Critical
instead of Error
.Logs with critical level can trigger some additional events in application with CriticalHandleFunc
set in logger using WithCriticalHandler
function. Logger does nothing in case of critical errors by default.
Logger will ignore all handlers errors by default. There is FailureHandleFunc
that can be implemented and added to logger
using WithFailureHandler
function. Whenever the handler returns error, this function will be triggered with Log
and
error as parameters.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.