gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

entry.go (3156B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package log
     19 
     20 import (
     21 	"context"
     22 	"fmt"
     23 	"syscall"
     24 
     25 	"codeberg.org/gruf/go-kv"
     26 	"codeberg.org/gruf/go-logger/v2/level"
     27 )
     28 
     29 type Entry struct {
     30 	ctx context.Context
     31 	kvs []kv.Field
     32 }
     33 
     34 func (e Entry) WithContext(ctx context.Context) Entry {
     35 	e.ctx = ctx
     36 	return e
     37 }
     38 
     39 func (e Entry) WithField(key string, value interface{}) Entry {
     40 	e.kvs = append(e.kvs, kv.Field{K: key, V: value})
     41 	return e
     42 }
     43 
     44 func (e Entry) WithFields(kvs ...kv.Field) Entry {
     45 	e.kvs = append(e.kvs, kvs...)
     46 	return e
     47 }
     48 
     49 func (e Entry) Trace(a ...interface{}) {
     50 	logf(e.ctx, 3, level.TRACE, e.kvs, args(len(a)), a...)
     51 }
     52 
     53 func (e Entry) Tracef(s string, a ...interface{}) {
     54 	logf(e.ctx, 3, level.TRACE, e.kvs, s, a...)
     55 }
     56 
     57 func (e Entry) Debug(a ...interface{}) {
     58 	logf(e.ctx, 3, level.DEBUG, e.kvs, args(len(a)), a...)
     59 }
     60 
     61 func (e Entry) Debugf(s string, a ...interface{}) {
     62 	logf(e.ctx, 3, level.DEBUG, e.kvs, s, a...)
     63 }
     64 
     65 func (e Entry) Info(a ...interface{}) {
     66 	logf(e.ctx, 3, level.INFO, e.kvs, args(len(a)), a...)
     67 }
     68 
     69 func (e Entry) Infof(s string, a ...interface{}) {
     70 	logf(e.ctx, 3, level.INFO, e.kvs, s, a...)
     71 }
     72 
     73 func (e Entry) Warn(a ...interface{}) {
     74 	logf(e.ctx, 3, level.WARN, e.kvs, args(len(a)), a...)
     75 }
     76 
     77 func (e Entry) Warnf(s string, a ...interface{}) {
     78 	logf(e.ctx, 3, level.WARN, e.kvs, s, a...)
     79 }
     80 
     81 func (e Entry) Error(a ...interface{}) {
     82 	logf(e.ctx, 3, level.ERROR, e.kvs, args(len(a)), a...)
     83 }
     84 
     85 func (e Entry) Errorf(s string, a ...interface{}) {
     86 	logf(e.ctx, 3, level.ERROR, e.kvs, s, a...)
     87 }
     88 
     89 func (e Entry) Fatal(a ...interface{}) {
     90 	defer syscall.Exit(1)
     91 	logf(e.ctx, 3, level.FATAL, e.kvs, args(len(a)), a...)
     92 }
     93 
     94 func (e Entry) Fatalf(s string, a ...interface{}) {
     95 	defer syscall.Exit(1)
     96 	logf(e.ctx, 3, level.FATAL, e.kvs, s, a...)
     97 }
     98 
     99 func (e Entry) Panic(a ...interface{}) {
    100 	defer panic(fmt.Sprint(a...))
    101 	logf(e.ctx, 3, level.PANIC, e.kvs, args(len(a)), a...)
    102 }
    103 
    104 func (e Entry) Panicf(s string, a ...interface{}) {
    105 	defer panic(fmt.Sprintf(s, a...))
    106 	logf(e.ctx, 3, level.PANIC, e.kvs, s, a...)
    107 }
    108 
    109 func (e Entry) Log(lvl level.LEVEL, a ...interface{}) {
    110 	logf(e.ctx, 3, lvl, e.kvs, args(len(a)), a...)
    111 }
    112 
    113 func (e Entry) Logf(lvl level.LEVEL, s string, a ...interface{}) {
    114 	logf(e.ctx, 3, lvl, e.kvs, s, a...)
    115 }
    116 
    117 func (e Entry) Print(a ...interface{}) {
    118 	printf(3, e.kvs, args(len(a)), a...)
    119 }
    120 
    121 func (e Entry) Printf(s string, a ...interface{}) {
    122 	printf(3, e.kvs, s, a...)
    123 }