Skip to content

Commit

Permalink
Format the timestamp with RFC8601 standard
Browse files Browse the repository at this point in the history
This commit change all of the time format into RFC8601 format
to make it easier to integrate with other tools.

partial-issue: #19
  • Loading branch information
chenglch committed Feb 2, 2018
1 parent 4c92228 commit be12165
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions common/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
const (
PERIODIC_INTERVAL = time.Minute
PIPELINE_SEND_INTERVAL = 300 * time.Millisecond
RFC8601_SECOND = "2006-01-02T15:04:05Z0700"
RFC8601_MILLISECOND = "2006-01-02T15:04:05Z0700.000"
RFC8601_MICROSECOND = "2006-01-02T15:04:05Z0700.000000"
RFC8601_NANOSECOND = "2006-01-02T15:04:05Z0700.000000000"
CLIENT_CONGO_TYPE = iota
CLIENT_XCAT_TYPE
)
Expand Down Expand Up @@ -45,10 +49,10 @@ var (
"y": true,
}
PRECISION_FORMAT = map[string]string{
"second": "2006-01-02 15:04:05",
"millisecond": "2006-01-02 15:04:05.000",
"microsecond": "2006-01-02 15:04:05.000000",
"nanosecond": "2006-01-02 15:04:05.000000000"}
"second": RFC8601_SECOND,
"millisecond": RFC8601_MILLISECOND,
"microsecond": RFC8601_MICROSECOND,
"nanosecond": RFC8601_NANOSECOND}
)

type FileCfg struct {
Expand Down Expand Up @@ -128,7 +132,7 @@ func InitServerConfig(confFile string) (*ServerConfig, error) {
serverConfig.Console.DataDir = "/var/lib/goconserver/"
serverConfig.Console.LogTimestamp = true
serverConfig.Console.TimePrecision = "microsecond"
serverConfig.Console.TimeFormat = "2006-01-02 15:04:05.000000"
serverConfig.Console.TimeFormat = RFC8601_MICROSECOND
serverConfig.Console.ReplayLines = 30
serverConfig.Console.ClientTimeout = 30
serverConfig.Console.TargetTimeout = 30
Expand Down
2 changes: 1 addition & 1 deletion console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (self *Console) writeClient(conn net.Conn) {
var ok bool
clientTimeout := time.Duration(serverConfig.Console.ClientTimeout)
welcome := fmt.Sprintf("goconserver(%s): Hello %s, welcome to the session of %s",
time.Now().Format("2006-01-02 15:04:05"), conn.RemoteAddr().String(), self.node.StorageNode.Name)
time.Now().Format(common.RFC8601_SECOND), conn.RemoteAddr().String(), self.node.StorageNode.Name)
err := common.Network.SendByteWithLengthTimeout(conn, []byte(welcome+"\r\n"), clientTimeout)
if err != nil {
plog.InfoNode(self.node.StorageNode.Name, fmt.Sprintf("Failed to send message to client. Error:%s", err.Error()))
Expand Down
4 changes: 2 additions & 2 deletions console/pipeline/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (self *ByteLogger) insertStamp(b []byte, newLine *bool) ([]byte, error) {
}()
for i := 0; i < len(b); i++ {
if *newLine {
buf.WriteString("\n[" + time.Now().Format("2006-01-02 15:04:05") + "] ")
buf.WriteString("\n[" + time.Now().Format(common.RFC8601_SECOND) + "] ")
*newLine = false
}
if b[i] == '\n' {
Expand Down Expand Up @@ -265,7 +265,7 @@ func (self *ByteLogger) Prompt(node string, message string) error {
message = message + "\r\n"
}
if serverConfig.Console.LogTimestamp {
message = "\r\n[" + time.Now().Format("2006-01-02 15:04:05") + "] " + message
message = "\r\n[" + time.Now().Format(common.RFC8601_SECOND) + "] " + message
}
for _, publisher := range self.publishers {
err = publisher.Publish(node, []byte(message))
Expand Down

0 comments on commit be12165

Please sign in to comment.