-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[standard]move event to logger package, and provide logger.
- Loading branch information
Showing
9 changed files
with
237 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# logger | ||
|
||
The `logger` package provides "event manager", "basic event definitions", and "a simple log transmitter". | ||
|
||
- **Event Manager**: Used to receive events and dispatch them to all subscribers. | ||
- **Event Definition**: Defines the most basic events, allowing for extension. | ||
- **Log Transmitter**: The event manager can derive a log transmitter, | ||
allowing log events to be passed to the log transmitter when events occur. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2023 - 2024. vistart. All rights reserved. | ||
// Use of this source code is governed by Apache-2.0 license | ||
// that can be found in the LICENSE file. | ||
|
||
package logger | ||
|
||
// Interface defines the methods that should be implemented to record events. | ||
type Interface interface { | ||
// Log records the event. | ||
// | ||
// Note that this method is actually executed asynchronously. | ||
Log(event EventInterface) | ||
} | ||
|
||
// Logger implements a simple log transmitter. | ||
type Logger struct { | ||
// eventChannel stores the event manager's event receiving channel. | ||
// | ||
// Note that this channel must be initialized, otherwise it will cause a panicking. | ||
eventChannel chan EventInterface | ||
Interface | ||
} | ||
|
||
// Log records the event. | ||
func (l *Logger) Log(event EventInterface) { | ||
l.eventChannel <- event | ||
} | ||
|
||
// NewLogger instantiates a new logger. | ||
func NewLogger(eventChannel chan EventInterface) Interface { | ||
return &Logger{ | ||
eventChannel: eventChannel, | ||
} | ||
} |
Oops, something went wrong.