Add documentation
This commit is contained in:
1 parent
69d0bdabf4
commit
6dab89a1d4
144 files changed
+1107
-549
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Handler for some CSS data for the web logger.
|
||||
func HandlerCSSNormalize(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
if Shutdown.IsDown() {
|
||||
@@ -19,6 +20,7 @@ func HandlerCSSNormalize(response http.ResponseWriter, request *http.Request) {
|
||||
fmt.Fprint(response, Assets.CSSNormalize)
|
||||
}
|
||||
|
||||
// Handler for some CSS data for the web logger.
|
||||
func HandlerCSSWebflow(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
if Shutdown.IsDown() {
|
||||
@@ -30,6 +32,7 @@ func HandlerCSSWebflow(response http.ResponseWriter, request *http.Request) {
|
||||
fmt.Fprint(response, Assets.CSSWebflow)
|
||||
}
|
||||
|
||||
// Handler for some CSS data for the web logger.
|
||||
func HandlerCSSLog(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
if Shutdown.IsDown() {
|
||||
@@ -41,6 +44,7 @@ func HandlerCSSLog(response http.ResponseWriter, request *http.Request) {
|
||||
fmt.Fprint(response, Assets.CSSLog)
|
||||
}
|
||||
|
||||
// Handler for some JS for the web logger.
|
||||
func HandlerJSModernizr(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
if Shutdown.IsDown() {
|
||||
@@ -52,6 +56,7 @@ func HandlerJSModernizr(response http.ResponseWriter, request *http.Request) {
|
||||
fmt.Fprint(response, Assets.JSModernizr)
|
||||
}
|
||||
|
||||
// Handler for some JS for the web logger.
|
||||
func HandlerJSWebflow(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
if Shutdown.IsDown() {
|
||||
@@ -63,6 +68,7 @@ func HandlerJSWebflow(response http.ResponseWriter, request *http.Request) {
|
||||
fmt.Fprint(response, Assets.JSWebflow)
|
||||
}
|
||||
|
||||
// Handler for some JS for the web logger.
|
||||
func HandlerJSjQuery(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
if Shutdown.IsDown() {
|
||||
@@ -74,6 +80,7 @@ func HandlerJSjQuery(response http.ResponseWriter, request *http.Request) {
|
||||
fmt.Fprint(response, Assets.JSjQuery)
|
||||
}
|
||||
|
||||
// Handler for some JS for the web logger.
|
||||
func HandlerJSjQueryMap(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
if Shutdown.IsDown() {
|
||||
|
||||
@@ -11,30 +11,32 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Handler for accessing the web logging.
|
||||
func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
||||
|
||||
// Case: The system goes down now.
|
||||
if Shutdown.IsDown() {
|
||||
http.NotFound(response, request)
|
||||
return
|
||||
}
|
||||
|
||||
// Execute the HTTP form:
|
||||
request.ParseForm()
|
||||
countParameters := len(request.Form)
|
||||
|
||||
// Setup the data for the HTML template:
|
||||
data := Scheme.Viewer{}
|
||||
data.Title = `Web Log Viewer`
|
||||
data.Sender = DeviceDatabase.ReadSenderNames()
|
||||
data.MessageNames = DeviceDatabase.ReadMessageNames()
|
||||
|
||||
// To less parameters?
|
||||
if countParameters < 9 {
|
||||
|
||||
// Initial view => refresh & first page (latest logs)
|
||||
data.Events = readLatest()
|
||||
data.SetLiveView = true
|
||||
|
||||
} else {
|
||||
|
||||
// Custom view
|
||||
// Case: Custom view
|
||||
currentLevel := request.FormValue(`Level`)
|
||||
currentTimeRange := request.FormValue(`timeRange`)
|
||||
currentCategory := request.FormValue(`Category`)
|
||||
@@ -45,6 +47,7 @@ func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
||||
currentPage := request.FormValue(`CurrentPage`)
|
||||
currentLiveView := request.FormValue(`LiveView`)
|
||||
|
||||
// Store the events for the template:
|
||||
data.Events = readCustom(currentTimeRange, currentLevel, currentCategory, currentImpact, currentSeverity, currentMessageName, currentSender, currentPage)
|
||||
|
||||
if strings.ToLower(currentLiveView) == `true` {
|
||||
@@ -94,6 +97,7 @@ func HandlerWebLog(response http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// Write the MIME type and execute the template:
|
||||
MimeTypes.Write2HTTP(response, MimeTypes.TypeWebHTML)
|
||||
if executeError := templates.ExecuteTemplate(response, `WebLog`, data); executeError != nil {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactCritical, LM.MessageNameEXECUTE, `Was not able to execute the web log viewer template.`, executeError.Error())
|
||||
|
||||
@@ -7,11 +7,13 @@ import (
|
||||
"html/template"
|
||||
)
|
||||
|
||||
// The init function for this package.
|
||||
func init() {
|
||||
|
||||
Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameINIT, `Init the web log.`)
|
||||
defer Log.LogShort(senderName, LM.CategorySYSTEM, LM.LevelINFO, LM.MessageNameINIT, `Init the web log done.`)
|
||||
|
||||
// Create the cache of all web logging templates:
|
||||
templates = template.New(`root`)
|
||||
if _, err := templates.Parse(WebTemp.Viewer); err != nil {
|
||||
Log.LogFull(senderName, LM.CategorySYSTEM, LM.LevelERROR, LM.SeverityCritical, LM.ImpactUnknown, LM.MessageNamePARSE, `Was not able to parse the template for the web log viewer.`, err.Error())
|
||||
|
||||
@@ -7,18 +7,24 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Read a custom event range from the database.
|
||||
func readCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage string) (events []Scheme.LogEvent) {
|
||||
|
||||
// Get the custom events:
|
||||
eventsFromDB := DeviceDatabase.ReadCustom(timeRange, logLevel, logCategory, logImpact, logSeverity, logMessageName, logSender, logPage)
|
||||
count := len(eventsFromDB)
|
||||
|
||||
// Array with all events, prepared for the website:
|
||||
events = make([]Scheme.LogEvent, count)
|
||||
|
||||
// Copy each event to the right format:
|
||||
for n := 0; n < count; n++ {
|
||||
eventFromDB := eventsFromDB[n]
|
||||
events[n] = Scheme.LogEvent{}
|
||||
events[n].LogLine = eventFromDB.Format()
|
||||
events[n].LogLevel = fmt.Sprintf("log%s", strings.ToLower(eventFromDB.Level[2:]))
|
||||
|
||||
// Vary the color of each line:
|
||||
if n%2 == 0 {
|
||||
events[n].AB = Scheme.B
|
||||
} else {
|
||||
|
||||
@@ -7,18 +7,23 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Read the latest log events from the database
|
||||
func readLatest() (events []Scheme.LogEvent) {
|
||||
|
||||
// Get the latest events from the database
|
||||
eventsFromDB := DeviceDatabase.ReadLatest()
|
||||
count := len(eventsFromDB)
|
||||
|
||||
// Array for the log events, prepared for the website:
|
||||
events = make([]Scheme.LogEvent, count)
|
||||
|
||||
// Copy each event to the right format for the website:
|
||||
for n := 0; n < count; n++ {
|
||||
eventFromDB := eventsFromDB[n]
|
||||
events[n] = Scheme.LogEvent{}
|
||||
events[n].LogLine = eventFromDB.Format()
|
||||
events[n].LogLevel = fmt.Sprintf("log%s", strings.ToLower(eventFromDB.Level[2:]))
|
||||
|
||||
// Vary the color of each line:
|
||||
if n%2 == 0 {
|
||||
events[n].AB = Scheme.B
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package Scheme
|
||||
|
||||
const (
|
||||
A string = `loga`
|
||||
B string = `logb`
|
||||
A string = `loga` // Web log line, kind A (different color for each line)
|
||||
B string = `logb` // Web log line, kind B (different color for each line)
|
||||
)
|
||||
@@ -1,5 +1,6 @@
|
||||
package Scheme
|
||||
|
||||
// The type for the web logger viewer template
|
||||
type Viewer struct {
|
||||
Title string
|
||||
SetLiveView bool
|
||||
@@ -16,12 +17,7 @@ type Viewer struct {
|
||||
Events []LogEvent
|
||||
}
|
||||
|
||||
// <li class="logline loga logwarn">
|
||||
// <div>....</div>
|
||||
// </li>
|
||||
// <li class="logline logb logwarn">
|
||||
// <div>....</div>
|
||||
// </li>
|
||||
// Type for a log event
|
||||
type LogEvent struct {
|
||||
LogLine string
|
||||
LogLevel string // logwarn || logdebug || logerror || loginfo || logtalkative || logsecurity
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package Templates
|
||||
|
||||
// The template for the web log viewer:
|
||||
var Viewer string = `
|
||||
{{define "WebLog"}}
|
||||
<!DOCTYPE html>
|
||||
|
||||
@@ -6,6 +6,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
templates *template.Template = nil
|
||||
senderName LM.Sender = `System::WebLog`
|
||||
templates *template.Template = nil // The web logging templates
|
||||
senderName LM.Sender = `System::WebLog` // This is the name for logging event from this package
|
||||
)
|
||||
Reference in new issue
Block a user