github.com/goravel/framework@v1.13.9/contracts/log/log.go (about) 1 package log 2 3 import ( 4 "context" 5 "time" 6 7 "github.com/goravel/framework/contracts/http" 8 ) 9 10 const ( 11 StackDriver = "stack" 12 SingleDriver = "single" 13 DailyDriver = "daily" 14 CustomDriver = "custom" 15 ) 16 17 const ( 18 PanicLevel Level = iota 19 FatalLevel 20 ErrorLevel 21 WarningLevel 22 InfoLevel 23 DebugLevel 24 ) 25 26 //go:generate mockery --name=Log 27 type Log interface { 28 // WithContext adds a context to the logger. 29 WithContext(ctx context.Context) Writer 30 Writer 31 } 32 33 //go:generate mockery --name=Writer 34 type Writer interface { 35 // Debug logs a message at DebugLevel. 36 Debug(args ...any) 37 // Debugf is equivalent to Debug, but with support for fmt.Printf-style arguments. 38 Debugf(format string, args ...any) 39 // Info logs a message at InfoLevel. 40 Info(args ...any) 41 // Infof is equivalent to Info, but with support for fmt.Printf-style arguments. 42 Infof(format string, args ...any) 43 // Warning logs a message at WarningLevel. 44 Warning(args ...any) 45 // Warningf is equivalent to Warning, but with support for fmt.Printf-style arguments. 46 Warningf(format string, args ...any) 47 // Error logs a message at ErrorLevel. 48 Error(args ...any) 49 // Errorf is equivalent to Error, but with support for fmt.Printf-style arguments. 50 Errorf(format string, args ...any) 51 // Fatal logs a message at FatalLevel. 52 Fatal(args ...any) 53 // Fatalf is equivalent to Fatal, but with support for fmt.Printf-style arguments. 54 Fatalf(format string, args ...any) 55 // Panic logs a message at PanicLevel. 56 Panic(args ...any) 57 // Panicf is equivalent to Panic, but with support for fmt.Printf-style arguments. 58 Panicf(format string, args ...any) 59 // Code set a code or slug that describes the error. 60 // Error messages are intended to be read by humans, but such code is expected to 61 // be read by machines and even transported over different services. 62 Code(code string) Writer 63 // Hint set a hint for faster debugging. 64 Hint(hint string) Writer 65 // In sets the feature category or domain in which the log entry is relevant. 66 In(domain string) Writer 67 // Owner set the name/email of the colleague/team responsible for handling this error. 68 // Useful for alerting purpose. 69 Owner(owner any) Writer 70 // Request supplies a http.Request. 71 Request(req http.ContextRequest) Writer 72 // Response supplies a http.Response. 73 Response(res http.ContextResponse) Writer 74 // Tags add multiple tags, describing the feature returning an error. 75 Tags(tags ...string) Writer 76 // User sets the user associated with the log entry. 77 User(user any) Writer 78 // With adds key-value pairs to the context of the log entry 79 With(data map[string]any) Writer 80 } 81 82 //go:generate mockery --name=Logger 83 type Logger interface { 84 // Handle pass a channel config path here 85 Handle(channel string) (Hook, error) 86 } 87 88 //go:generate mockery --name=Hook 89 type Hook interface { 90 // Levels monitoring level 91 Levels() []Level 92 // Fire executes logic when trigger 93 Fire(Entry) error 94 } 95 96 //go:generate mockery --name=Entry 97 type Entry interface { 98 // Context returns the context of the entry. 99 Context() context.Context 100 // Level returns the level of the entry. 101 Level() Level 102 // Time returns the timestamp of the entry. 103 Time() time.Time 104 // Message returns the message of the entry. 105 Message() string 106 }