logger

package
v2.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 1 Imported by: 0

README

Logging in Cloudinary SDK

The default logger in Cloudinary Go SDK is go log.

You can use any log library by overwriting the standard SDK logging functions.

Using logrus with the SDK

package main

import (
	"github.com/cloudinary/cloudinary-go"
	"github.com/sirupsen/logrus"
	"log"
)

func main() {
	// Start by creating a new instance of Cloudinary using CLOUDINARY_URL environment variable.
	// Alternatively you can use cloudinary.NewFromParams() or cloudinary.NewFromURL().
	var cld, err = cloudinary.New()
	if err != nil {
		log.Fatalf("Failed to intialize Cloudinary, %v", err)
	}

	// Initialize your logger somewhere in your code.
	// Set cloudinary.Logger.Writer with logrus instance
	var logger = logrus.New()
	cld.Logger.Writer = logger.WithField("source", "cloudinary")
}

Using Zap with the SDK

package main

import (
	"github.com/cloudinary/cloudinary-go"
	"go.uber.org/zap"
	"log"
)

func main() {
	// Start by creating a new instance of Cloudinary using CLOUDINARY_URL environment variable.
	// Alternatively you can use cloudinary.NewFromParams() or cloudinary.NewFromURL().
	var cld, err = cloudinary.New()
	if err != nil {
		log.Fatalf("Failed to intialize Cloudinary, %v", err)
	}

	// Initialize your logger somewhere in your code.
	// Set cloudinary.Logger.Writer with zap.SugaredLogger instance
	var zapLogger, _ = zap.NewDevelopment()
	cld.Logger.Writer = zapLogger.Sugar().With("source", "cloudinary")
}

Logging level

You can change logging level with the Logger.SetLevel() function.

Possible values:

  • logger.NONE - disabling logging from the SDK
  • logger.ERROR - enable logging only for error messages
  • logger.DEBUG - enable debug logs

Documentation

Overview

Package logger defines the Cloudinary Logger

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoLog

type GoLog struct{}

GoLog is a struct for go log writer.

func (*GoLog) Debug

func (g *GoLog) Debug(v ...interface{})

Debug prints debug messages.

func (*GoLog) Error

func (g *GoLog) Error(v ...interface{})

Error prints error messages.

type Level

type Level int8

Level represents the level of the logger.

const DEBUG Level = 2

DEBUG level of the logger.

const ERROR Level = 1

ERROR level of the logger.

const NONE Level = 0

NONE level of the logger.

type LogWriter

type LogWriter interface {
	Debug(v ...interface{})
	Error(v ...interface{})
}

LogWriter is an interface for a log writer.

type Logger

type Logger struct {
	Writer LogWriter
	// contains filtered or unexported fields
}

Logger is the logger struct.

func New

func New() *Logger

New returns a new logger instance.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug writes debug messages.

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Debug writes error messages.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel sets the logger level.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL