github.com/MontFerret/ferret@v0.18.0/pkg/stdlib/utils/log.go (about)

     1  package utils
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/MontFerret/ferret/pkg/runtime/core"
     7  	"github.com/MontFerret/ferret/pkg/runtime/logging"
     8  	"github.com/MontFerret/ferret/pkg/runtime/values"
     9  )
    10  
    11  // PRINT writes messages into the system log.
    12  // @param {Value, repeated} message - Print message.
    13  func Print(ctx context.Context, args ...core.Value) (core.Value, error) {
    14  	err := core.ValidateArgs(args, 1, core.MaxArgs)
    15  
    16  	if err != nil {
    17  		return values.None, err
    18  	}
    19  
    20  	messages := make([]interface{}, 0, len(args))
    21  
    22  	for idx, input := range args {
    23  		if idx == 0 {
    24  			messages = append(messages, input)
    25  		} else {
    26  			messages = append(messages, " "+input.String())
    27  		}
    28  	}
    29  
    30  	logger := logging.FromContext(ctx)
    31  
    32  	logger.Print(messages...)
    33  
    34  	return values.None, nil
    35  }