Initial commit of Ocean's local development
This commit is contained in:
1 parent
9944a9e1df
commit
86451938ec
116 files changed
+3320
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package Meta
|
||||
|
||||
type Category byte
|
||||
|
||||
const (
|
||||
CategoryBUSINESS = Category(iota)
|
||||
CategorySYSTEM = Category(iota)
|
||||
CategoryAPP = Category(iota)
|
||||
CategoryUSER = Category(iota)
|
||||
)
|
||||
|
||||
func FormatCategory(cat Category) (result string) {
|
||||
switch cat {
|
||||
case CategoryBUSINESS:
|
||||
result = `C:BUSINESS`
|
||||
case CategoryAPP:
|
||||
result = `C:APP`
|
||||
case CategorySYSTEM:
|
||||
result = `C:SYSTEM`
|
||||
case CategoryUSER:
|
||||
result = `C:USER`
|
||||
default:
|
||||
result = `C:N/A`
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package Meta
|
||||
|
||||
import "time"
|
||||
|
||||
type Entry struct {
|
||||
Project string
|
||||
Time time.Time
|
||||
Sender Sender
|
||||
Category Category
|
||||
Level Level
|
||||
Severity Severity
|
||||
Impact Impact
|
||||
MessageName MessageName
|
||||
MessageDescription string
|
||||
Parameters []string
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package Meta
|
||||
|
||||
import "fmt"
|
||||
import "time"
|
||||
import "strconv"
|
||||
import "strings"
|
||||
|
||||
func (entry Entry) Format() (result string) {
|
||||
|
||||
lenSender := len(entry.Sender)
|
||||
if lenSender > 40 {
|
||||
lenSender = 40
|
||||
}
|
||||
|
||||
lenMessageName := len(entry.MessageName)
|
||||
if lenMessageName > 26 {
|
||||
lenMessageName = 26
|
||||
}
|
||||
|
||||
lenProject := len(entry.Project)
|
||||
if lenProject > 10 {
|
||||
lenProject = 10
|
||||
}
|
||||
|
||||
messageDescription := entry.MessageDescription
|
||||
messageDescription = strings.Replace(messageDescription, `\n`, ` `, -1)
|
||||
messageDescription = strings.Replace(messageDescription, `\t`, ` `, -1)
|
||||
messageDescription = strings.Replace(messageDescription, `\r`, ` `, -1)
|
||||
|
||||
result = fmt.Sprintf(` [■] P:%10s [■] %s [■] %10s [■] %11s [■] %10s [■] %10s [■] sender: %-40s [■] name: %-26s [■] %s [■]`, entry.Project[:lenProject], formatTime(entry.Time), FormatCategory(entry.Category), FormatLevel(entry.Level), FormatSeverity(entry.Severity), FormatImpact(entry.Impact), entry.Sender[:lenSender], entry.MessageName[:lenMessageName], messageDescription)
|
||||
|
||||
for _, param := range entry.Parameters {
|
||||
|
||||
paramText := param
|
||||
paramText = strings.Replace(paramText, `\n`, ` `, -1)
|
||||
paramText = strings.Replace(paramText, `\t`, ` `, -1)
|
||||
paramText = strings.Replace(paramText, `\r`, ` `, -1)
|
||||
|
||||
result = fmt.Sprintf(`%s %s [■]`, result, paramText)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func formatTime(t1 time.Time) (result string) {
|
||||
var year int = t1.Year()
|
||||
var month int = int(t1.Month())
|
||||
var day int = int(t1.Day())
|
||||
var minutes int = int(t1.Minute())
|
||||
var hours int = int(t1.Hour())
|
||||
var seconds int = int(t1.Second())
|
||||
var milliseconds int = int(float64(t1.Nanosecond()) / 1000000.0)
|
||||
|
||||
var monthText, dayText, minutesText, hoursText, secondsText, millisecondsText string
|
||||
|
||||
if month >= 1 && month <= 9 {
|
||||
monthText = fmt.Sprintf(`0%d`, month)
|
||||
} else {
|
||||
monthText = strconv.Itoa(month)
|
||||
}
|
||||
|
||||
if day >= 1 && day <= 9 {
|
||||
dayText = fmt.Sprintf(`0%d`, day)
|
||||
} else {
|
||||
dayText = strconv.Itoa(day)
|
||||
}
|
||||
|
||||
if minutes >= 0 && minutes <= 9 {
|
||||
minutesText = fmt.Sprintf(`0%d`, minutes)
|
||||
} else {
|
||||
minutesText = strconv.Itoa(minutes)
|
||||
}
|
||||
|
||||
if hours >= 0 && hours <= 9 {
|
||||
hoursText = fmt.Sprintf(`0%d`, hours)
|
||||
} else {
|
||||
hoursText = strconv.Itoa(hours)
|
||||
}
|
||||
|
||||
if seconds >= 0 && seconds <= 9 {
|
||||
secondsText = fmt.Sprintf(`0%d`, seconds)
|
||||
} else {
|
||||
secondsText = strconv.Itoa(seconds)
|
||||
}
|
||||
|
||||
if milliseconds >= 0 && milliseconds <= 9 {
|
||||
millisecondsText = fmt.Sprintf(`00%d`, milliseconds)
|
||||
} else if milliseconds >= 10 && milliseconds <= 99 {
|
||||
millisecondsText = fmt.Sprintf(`0%d`, milliseconds)
|
||||
} else {
|
||||
millisecondsText = strconv.Itoa(milliseconds)
|
||||
}
|
||||
|
||||
result = fmt.Sprintf(`%d%s%s %s%s%s.%s`, year, monthText, dayText, hoursText, minutesText, secondsText, millisecondsText)
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package Meta
|
||||
|
||||
type Impact byte
|
||||
|
||||
const (
|
||||
ImpactNone = Impact(iota)
|
||||
ImpactLow = Impact(iota)
|
||||
ImpactMiddle = Impact(iota)
|
||||
ImpactHigh = Impact(iota)
|
||||
ImpactCritical = Impact(iota)
|
||||
ImpactUnknown = Impact(iota)
|
||||
)
|
||||
|
||||
func FormatImpact(pri Impact) (result string) {
|
||||
switch pri {
|
||||
case ImpactCritical:
|
||||
result = `I:CRITICAL`
|
||||
case ImpactHigh:
|
||||
result = `I:HIGH`
|
||||
case ImpactLow:
|
||||
result = `I:LOW`
|
||||
case ImpactMiddle:
|
||||
result = `I:MIDDLE`
|
||||
case ImpactNone:
|
||||
result = `I:NONE`
|
||||
case ImpactUnknown:
|
||||
result = `I:UNKNOWN`
|
||||
default:
|
||||
result = `I:N/A`
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package Meta
|
||||
|
||||
type Level byte
|
||||
|
||||
const (
|
||||
LevelWARN = Level(iota)
|
||||
LevelDEBUG = Level(iota)
|
||||
LevelERROR = Level(iota)
|
||||
LevelINFO = Level(iota)
|
||||
LevelTALKATIVE = Level(iota)
|
||||
LevelSECURITY = Level(iota)
|
||||
)
|
||||
|
||||
func FormatLevel(lvl Level) (result string) {
|
||||
switch lvl {
|
||||
case LevelDEBUG:
|
||||
result = `L:DEBUG`
|
||||
case LevelERROR:
|
||||
result = `L:ERROR`
|
||||
case LevelINFO:
|
||||
result = `L:INFO`
|
||||
case LevelSECURITY:
|
||||
result = `L:SECURITY`
|
||||
case LevelTALKATIVE:
|
||||
result = `L:TALKATIVE`
|
||||
case LevelWARN:
|
||||
result = `L:WARN`
|
||||
default:
|
||||
result = `L:N/A`
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package Meta
|
||||
|
||||
type MessageName string
|
||||
|
||||
const (
|
||||
MessageNameSTARTUP = `Startup`
|
||||
MessageNameINIT = `Init`
|
||||
MessageNameSHUTDOWN = `Shutdown`
|
||||
MessageNameEXECUTE = `Execute`
|
||||
MessageNameDATABASE = `Database`
|
||||
MessageNameNETWORK = `Network`
|
||||
MessageNameLOGIN = `Login`
|
||||
MessageNameLOGOUT = `Logout`
|
||||
MessageNameSESSION = `Session`
|
||||
MessageNameTIMEOUT = `Timeout`
|
||||
MessageNameFILESYSTEM = `Filesystem`
|
||||
MessageNameCOMMUNICATION = `Communication`
|
||||
MessageNameWRITE = `Write`
|
||||
MessageNameREAD = `Read`
|
||||
MessageNameALGORITHM = `Algorithm`
|
||||
MessageNameCONFIGURATION = `Configuration`
|
||||
MessageNameTIMER = `Timer`
|
||||
MessageNameINPUT = `Input`
|
||||
MessageNameOUTPUT = `Output`
|
||||
MessageNameBROWSER = `Browser`
|
||||
MessageNameSECURITY = `Security`
|
||||
MessageNameNOTFOUND = `NotFound`
|
||||
MessageNameANALYSIS = `Analysis`
|
||||
MessageNameSTATE = `State`
|
||||
MessageNameGENERATOR = `Generator`
|
||||
MessageNamePRODUCER = `Producer`
|
||||
MessageNameCONSUMER = `Consumer`
|
||||
MessageNamePASSWORD = `Password`
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
package Meta
|
||||
|
||||
type Sender string
|
||||
@@ -0,0 +1,33 @@
|
||||
package Meta
|
||||
|
||||
type Severity byte
|
||||
|
||||
const (
|
||||
SeverityNone = Severity(iota)
|
||||
SeverityLow = Severity(iota)
|
||||
SeverityMiddle = Severity(iota)
|
||||
SeverityHigh = Severity(iota)
|
||||
SeverityCritical = Severity(iota)
|
||||
SeverityUnknown = Severity(iota)
|
||||
)
|
||||
|
||||
func FormatSeverity(pri Severity) (result string) {
|
||||
switch pri {
|
||||
case SeverityCritical:
|
||||
result = `S:CRITICAL`
|
||||
case SeverityHigh:
|
||||
result = `S:HIGH`
|
||||
case SeverityLow:
|
||||
result = `S:LOW`
|
||||
case SeverityMiddle:
|
||||
result = `S:MIDDLE`
|
||||
case SeverityNone:
|
||||
result = `S:NONE`
|
||||
case SeverityUnknown:
|
||||
result = `S:UNKNOWN`
|
||||
default:
|
||||
result = `S:N/A`
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in new issue
Block a user