2014-12-08 20:53:00 +03:00
|
|
|
// +build windows
|
|
|
|
|
2014-08-13 20:28:28 +04:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
//
|
|
|
|
// Contributor: Julien Vehent jvehent@mozilla.com [:ulfr]
|
2015-08-26 21:15:40 +03:00
|
|
|
package mig /* import "mig.ninja/mig" */
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
|
2014-02-05 22:53:26 +04:00
|
|
|
import (
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
2014-07-30 21:09:43 +04:00
|
|
|
|
|
|
|
"code.google.com/p/winsvc/eventlog"
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
MODE_STDOUT = 1 << iota
|
|
|
|
MODE_FILE
|
2014-07-30 21:09:43 +04:00
|
|
|
MODE_EVENTLOG
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Logging stores the attributes needed to perform the logging
|
|
|
|
type Logging struct {
|
|
|
|
// configuration
|
|
|
|
Mode, Level, File, Host, Protocol, Facility string
|
2014-02-05 22:53:26 +04:00
|
|
|
Port int
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
// internal
|
2014-07-30 21:09:43 +04:00
|
|
|
logmode int
|
|
|
|
maxlvl int
|
|
|
|
fd *eventlog.Log
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Log defines a log entry
|
|
|
|
type Log struct {
|
2014-06-17 18:59:46 +04:00
|
|
|
OpID, ActionID, CommandID float64
|
2014-02-05 22:53:26 +04:00
|
|
|
Sev, Desc string
|
2014-07-30 21:09:43 +04:00
|
|
|
Priority int
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l Log) Emerg() (mlog Log) {
|
|
|
|
mlog = l
|
2014-07-30 21:09:43 +04:00
|
|
|
mlog.Priority = eventlog.Error
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
mlog.Sev = "emergency"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l Log) Alert() (mlog Log) {
|
|
|
|
mlog = l
|
2014-07-30 21:09:43 +04:00
|
|
|
mlog.Priority = eventlog.Error
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
mlog.Sev = "alert"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l Log) Crit() (mlog Log) {
|
|
|
|
mlog = l
|
2014-07-30 21:09:43 +04:00
|
|
|
mlog.Priority = eventlog.Error
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
mlog.Sev = "critical"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l Log) Err() (mlog Log) {
|
|
|
|
mlog = l
|
2014-07-30 21:09:43 +04:00
|
|
|
mlog.Priority = eventlog.Error
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
mlog.Sev = "error"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l Log) Warning() (mlog Log) {
|
|
|
|
mlog = l
|
2014-07-30 21:09:43 +04:00
|
|
|
mlog.Priority = eventlog.Warning
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
mlog.Sev = "warning"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l Log) Notice() (mlog Log) {
|
|
|
|
mlog = l
|
2014-07-30 21:09:43 +04:00
|
|
|
mlog.Priority = eventlog.Warning
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
mlog.Sev = "notice"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l Log) Info() (mlog Log) {
|
|
|
|
mlog = l
|
2014-07-30 21:09:43 +04:00
|
|
|
mlog.Priority = eventlog.Info
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
mlog.Sev = "info"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-07-30 21:09:43 +04:00
|
|
|
// don't log debug messages on windows
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
func (l Log) Debug() (mlog Log) {
|
|
|
|
mlog = l
|
2014-07-30 21:09:43 +04:00
|
|
|
mlog.Priority = 999
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
mlog.Sev = "debug"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// InitLogger prepares the context for logging based on the configuration
|
|
|
|
// in Logging
|
2014-06-10 01:28:43 +04:00
|
|
|
func InitLogger(orig_logctx Logging, progname string) (logctx Logging, err error) {
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
defer func() {
|
|
|
|
if e := recover(); e != nil {
|
|
|
|
err = fmt.Errorf("mig.InitLogger() -> %v", e)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
logctx = orig_logctx
|
|
|
|
switch logctx.Mode {
|
|
|
|
case "stdout":
|
|
|
|
logctx.logmode = MODE_STDOUT
|
|
|
|
logctx, err = initLogStdOut(logctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
case "file":
|
|
|
|
logctx.logmode = MODE_FILE
|
|
|
|
logctx, err = initLogFile(logctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
case "syslog":
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.logmode = MODE_EVENTLOG
|
|
|
|
logctx, err = initEventlog(logctx, progname)
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Println("Logging mode is missing. Assuming stdout.")
|
|
|
|
logctx.Mode = "stdout"
|
|
|
|
logctx.logmode = MODE_STDOUT
|
|
|
|
logctx, err = initLogStdOut(logctx)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the minimal log level
|
|
|
|
switch logctx.Level {
|
|
|
|
case "emerg":
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.maxlvl = eventlog.Error
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
case "alert":
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.maxlvl = eventlog.Error
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
case "crit":
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.maxlvl = eventlog.Error
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
case "err":
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.maxlvl = eventlog.Error
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
case "warning":
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.maxlvl = eventlog.Warning
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
case "notice":
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.maxlvl = eventlog.Warning
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
case "info":
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.maxlvl = eventlog.Info
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
case "debug":
|
2014-07-30 21:09:43 +04:00
|
|
|
// discard
|
|
|
|
logctx.maxlvl = 999
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-07-30 21:09:43 +04:00
|
|
|
// initEventlog creates a connection to event logs and stores the handler in ctx
|
|
|
|
func initEventlog(orig_logctx Logging, progname string) (logctx Logging, err error) {
|
|
|
|
logctx = orig_logctx
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
defer func() {
|
|
|
|
if e := recover(); e != nil {
|
2014-07-30 21:09:43 +04:00
|
|
|
err = fmt.Errorf("mig.initEventlog() -> %v", e)
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
}
|
|
|
|
}()
|
2014-07-30 21:09:43 +04:00
|
|
|
const name = "mylog"
|
|
|
|
const supports = eventlog.Error | eventlog.Warning | eventlog.Info
|
|
|
|
err = eventlog.InstallAsEventCreate(name, supports)
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-07-30 21:09:43 +04:00
|
|
|
logctx.fd, err = eventlog.Open(progname)
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// initLogFile creates a logfile and stores the descriptor in ctx
|
2014-02-05 22:53:26 +04:00
|
|
|
func initLogFile(orig_logctx Logging) (logctx Logging, err error) {
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
defer func() {
|
|
|
|
if e := recover(); e != nil {
|
|
|
|
err = fmt.Errorf("mig.InitLogFile() -> %v", e)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
logctx = orig_logctx
|
2014-02-05 22:53:26 +04:00
|
|
|
fd, err := os.OpenFile(logctx.File, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0640)
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
log.SetOutput(fd)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// initLogStdOut does nothing except storing in ctx that logs should be
|
|
|
|
// sent to stdout directly
|
2014-02-05 22:53:26 +04:00
|
|
|
func initLogStdOut(orig_logctx Logging) (logctx Logging, err error) {
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
logctx = orig_logctx
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// processLog receives events and perform logging and evaluationg of the log
|
|
|
|
// if the log is too critical, Analyze will trigger a scheduler shutdown
|
|
|
|
func ProcessLog(logctx Logging, l Log) (stop bool, err error) {
|
|
|
|
stop = false
|
|
|
|
defer func() {
|
|
|
|
if e := recover(); e != nil {
|
|
|
|
err = fmt.Errorf("mig.ProcessLog() -> %v", e)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
var logline string
|
|
|
|
|
|
|
|
// if priority isn't set, use the default "info"
|
|
|
|
if l.Priority < 1 {
|
2014-07-30 21:09:43 +04:00
|
|
|
l.Priority = eventlog.Info
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// discard logs that have a priority that's higher than the
|
2014-07-30 21:09:43 +04:00
|
|
|
// minimal log level we are configured to log
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
if l.Priority > logctx.maxlvl {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if l.OpID > 0 {
|
2014-06-17 23:44:53 +04:00
|
|
|
logline += fmt.Sprintf("%.0f ", l.OpID)
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
} else {
|
|
|
|
logline += "- "
|
|
|
|
}
|
|
|
|
|
|
|
|
if l.ActionID > 0 {
|
2014-06-17 23:44:53 +04:00
|
|
|
logline += fmt.Sprintf("%.0f ", l.ActionID)
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
} else {
|
|
|
|
logline += "- "
|
|
|
|
}
|
|
|
|
|
|
|
|
if l.CommandID > 0 {
|
2014-06-17 23:44:53 +04:00
|
|
|
logline += fmt.Sprintf("%.0f ", l.CommandID)
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
} else {
|
|
|
|
logline += "- "
|
|
|
|
}
|
|
|
|
|
|
|
|
if l.Sev != "" {
|
|
|
|
logline += "[" + l.Sev + "] "
|
|
|
|
} else {
|
|
|
|
logline += "[info] "
|
|
|
|
}
|
|
|
|
|
|
|
|
if l.Desc != "" {
|
|
|
|
logline += l.Desc
|
|
|
|
} else {
|
|
|
|
err = fmt.Errorf("Missing mandatory description in logent")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch logctx.logmode {
|
2014-07-30 21:09:43 +04:00
|
|
|
case MODE_EVENTLOG:
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
switch l.Priority {
|
2014-07-30 21:09:43 +04:00
|
|
|
case eventlog.Error:
|
|
|
|
err = logctx.fd.Error(1, logline)
|
2014-06-27 04:32:46 +04:00
|
|
|
return
|
2014-07-30 21:09:43 +04:00
|
|
|
case eventlog.Warning:
|
|
|
|
err = logctx.fd.Warning(2, logline)
|
2014-06-27 04:32:46 +04:00
|
|
|
return
|
2014-07-30 21:09:43 +04:00
|
|
|
case eventlog.Info:
|
|
|
|
err = logctx.fd.Info(3, logline)
|
2014-06-27 04:32:46 +04:00
|
|
|
return
|
2014-07-30 21:09:43 +04:00
|
|
|
case 999:
|
|
|
|
// debug logs go to stdout
|
|
|
|
log.Println(logline)
|
2014-06-27 04:32:46 +04:00
|
|
|
return
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
default:
|
2014-07-30 21:09:43 +04:00
|
|
|
err = logctx.fd.Info(3, logline)
|
2014-06-27 04:32:46 +04:00
|
|
|
return
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
}
|
|
|
|
case MODE_STDOUT:
|
|
|
|
log.Println(logline)
|
2014-06-27 04:32:46 +04:00
|
|
|
return
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
case MODE_FILE:
|
|
|
|
log.Println(logline)
|
2014-06-27 04:32:46 +04:00
|
|
|
return
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
default:
|
|
|
|
log.Println(logline)
|
2014-06-27 04:32:46 +04:00
|
|
|
return
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (logctx Logging) Destroy() {
|
|
|
|
if logctx.Mode == "syslog" {
|
2014-07-30 21:09:43 +04:00
|
|
|
_ = logctx.fd.Close()
|
Scheduler: Happy New Year, with a massive refactoring commit.
The logic is pretty much the same as before, but this commit is a massive code
cleanup. There is now:
* proper error handling: each function uses panic internally, with a defer block
that transform the panic into an error, and eventually logs
* syslog, log levels, asynchronous logging into LOG channel, and mig.LOG type
* configuration file, loaded into global Context, accessible to all functions
* Context initialization, with connection to database, broker, creation of channels
and other wonders is handled in context.go
* split of the scheduler code into several files, more work to do on that front,
particularly for the management of the Flow in flow.go
* Action and Command are split out in their own files, with specific methods
That's about it. Did I mention Happy New Year?
2014-01-07 00:59:27 +04:00
|
|
|
}
|
|
|
|
}
|