event

package
v0.0.0-...-c8acfb9 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package event provides a publish-subscribe event hub and a global logger.

Copyright (c) 2018 - 2024 PhotoPrism UG. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under Version 3 of the GNU Affero General Public License (the "AGPL"):
<https://docs.photoprism.app/license/agpl>

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

The AGPL is supplemented by our Trademark and Brand Guidelines,
which describe how our Brand Assets may be used:
<https://www.photoprism.app/trademark>

Feel free to send an email to hello@photoprism.app if you have questions, want to support our work, or just want to say hello.

Additional information can be found in our Developer Guide: <https://docs.photoprism.app/developer-guide/>

Index

Constants

View Source
const (
	EntityUpdated  = "updated"
	EntityCreated  = "created"
	EntityDeleted  = "deleted"
	EntityArchived = "archived"
	EntityRestored = "restored"
)
View Source
const Day = time.Hour * 24
View Source
const TopicSep = "."

Variables

View Source
var AuditMessageSep = " › "
View Source
var AuditPrefix = "audit: "
View Source
var TextFormatter = &logrus.TextFormatter{
	DisableColors: false,
	FullTimestamp: true,
}

TextFormatter for log messages.

Functions

func Audit

func Audit(level logrus.Level, ev []string, args ...interface{})

Audit optionally reports security-relevant events.

func AuditDebug

func AuditDebug(ev []string, args ...interface{})

func AuditErr

func AuditErr(ev []string, args ...interface{})

func AuditInfo

func AuditInfo(ev []string, args ...interface{})

func AuditWarn

func AuditWarn(ev []string, args ...interface{})

func EntitiesArchived

func EntitiesArchived(channel string, entities interface{})

func EntitiesCreated

func EntitiesCreated(channel string, entities interface{})

func EntitiesDeleted

func EntitiesDeleted(channel string, entities interface{})

func EntitiesRestored

func EntitiesRestored(channel string, entities interface{})

func EntitiesUpdated

func EntitiesUpdated(channel string, entities interface{})

func Error

func Error(msg string)

func ErrorMsg

func ErrorMsg(id i18n.Message, params ...interface{})

func Format

func Format(ev []string, args ...interface{}) string

Format formats an audit log event.

func Info

func Info(msg string)

func InfoMsg

func InfoMsg(id i18n.Message, params ...interface{})

func LoginError

func LoginError(ip, realm, name, browser, error string)

LoginError publishes a login error event.

func LoginInfo

func LoginInfo(ip, realm, name, browser string)

LoginInfo publishes a successful login event.

func Publish

func Publish(event string, data Data)

Publish publishes a message to all subscribers.

func PublishEntities

func PublishEntities(channel, ev string, entities interface{})

PublishEntities publishes updated entity data.

func PublishUserEntities

func PublishUserEntities(channel, ev string, entities interface{}, userUid string)

PublishUserEntities publishes updated entity data for a user.

func Seconds

func Seconds(s int) time.Duration

Seconds converts an int to a duration in seconds.

func Subscribe

func Subscribe(topics ...string) hub.Subscription

Subscribe creates a topic subscription and returns i

func Success

func Success(msg string)

func SuccessMsg

func SuccessMsg(id i18n.Message, params ...interface{})

func TimePointer

func TimePointer() *time.Time

TimePointer returns a pointer to the current timestamp.

func TimeStamp

func TimeStamp() time.Time

TimeStamp returns the current timestamp in UTC rounded to seconds.

func Topic

func Topic(topic string) (ch, ev string)

Topic splits the topic name into the channel and event names.

func Unsubscribe

func Unsubscribe(s hub.Subscription)

Unsubscribe deletes the subscription of a topic.

func Warn

func Warn(msg string)

func WarnMsg

func WarnMsg(id i18n.Message, params ...interface{})

func Yesterday

func Yesterday() time.Time

Yesterday returns the time 24 hours ago.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a goroutine safe buffer.

var LogBuffer Buffer

func (*Buffer) Get

func (b *Buffer) Get() string

Get returns the buffer content.

func (*Buffer) Set

func (b *Buffer) Set(s string) (err error)

Set updates the buffer content.

type Data

type Data = hub.Fields

func LoginData

func LoginData(level logrus.Level, ip, realm, name, browser, message string) Data

LoginData returns a login event message.

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook represents a log event hook.

func NewHook

func NewHook(hub *hub.Hub) *Hook

NewHook creates a new log event hook.

func (*Hook) Fire

func (h *Hook) Fire(entry *logrus.Entry) error

Fire publishes a new log event,

func (*Hook) Levels

func (h *Hook) Levels() []logrus.Level

Levels returns a slice containing all supported log levels.

type Hub

type Hub = hub.Hub

func NewHub

func NewHub() *Hub

func SharedHub

func SharedHub() *Hub

type LogWriter

type LogWriter struct {
	Log   Logger
	Level logrus.Level
}

LogWriter is an output writer wrapper for using Logrus with the standard logger.

func (*LogWriter) Write

func (w *LogWriter) Write(b []byte) (int, error)

Write implements io.Writer.

type Logger

type Logger interface {
	WithField(key string, value interface{}) *logrus.Entry
	WithFields(fields logrus.Fields) *logrus.Entry
	WithError(err error) *logrus.Entry
	WithContext(ctx context.Context) *logrus.Entry
	WithTime(t time.Time) *logrus.Entry
	Logf(level logrus.Level, format string, args ...interface{})
	Tracef(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Printf(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})
	Log(level logrus.Level, args ...interface{})
	LogFn(level logrus.Level, fn logrus.LogFunction)
	Trace(args ...interface{})
	Debug(args ...interface{})
	Info(args ...interface{})
	Print(args ...interface{})
	Warn(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})
	TraceFn(fn logrus.LogFunction)
	DebugFn(fn logrus.LogFunction)
	InfoFn(fn logrus.LogFunction)
	PrintFn(fn logrus.LogFunction)
	WarnFn(fn logrus.LogFunction)
	WarningFn(fn logrus.LogFunction)
	ErrorFn(fn logrus.LogFunction)
	FatalFn(fn logrus.LogFunction)
	PanicFn(fn logrus.LogFunction)
	Logln(level logrus.Level, args ...interface{})
	Traceln(args ...interface{})
	Debugln(args ...interface{})
	Infoln(args ...interface{})
	Println(args ...interface{})
	Warnln(args ...interface{})
	Warningln(args ...interface{})
	Errorln(args ...interface{})
	Fatalln(args ...interface{})
	Panicln(args ...interface{})
	Exit(code int)
	SetNoLock()
	SetLevel(level logrus.Level)
	GetLevel() logrus.Level
	AddHook(hook logrus.Hook)
	IsLevelEnabled(level logrus.Level) bool
	SetFormatter(formatter logrus.Formatter)
	SetOutput(output io.Writer)
	SetReportCaller(reportCaller bool)
	ReplaceHooks(hooks logrus.LevelHooks) logrus.LevelHooks
	SetBufferPool(pool logrus.BufferPool)
}

Logger is a logrus compatible logger interface.

var AuditLog Logger

AuditLog optionally logs security events.

var Log Logger

Log is the global default logger.

type Message

type Message = hub.Message

Jump to

Keyboard shortcuts

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