logger

package
Version: v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 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{}

func (*GoLog) Debug

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

func (*GoLog) Error

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

type Level

type Level int8
const DEBUG Level = 2
const ERROR Level = 1
const NONE Level = 0

type LogWriter

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

type Logger

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

func New

func New() *Logger

func (*Logger) Debug

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

func (*Logger) Error

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

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

Source Files

Jump to

Keyboard shortcuts

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