func safeLog(m *ModuleSupport, info *model.Module) *logger.Logger {
	if m == nil || m.Log == nil {
		return logger.GetLogger(fmt.Sprintf("%s.module", safeID(info)))
	} else {
		return m.Log
	}
}
this function will always return a logger that can be used even if the
support object has not been initialized in the correct sequence or with
the correct arguments.
package support
import (
	"fmt"
	"github.com/juju/loggo"
	"github.com/ninjasphere/go-ninja/api"
	"github.com/ninjasphere/go-ninja/logger"
	"github.com/ninjasphere/go-ninja/model"
)
type ModuleSupport struct {
	Info   *model.Module
	Log    *logger.Logger
	Conn   *ninja.Connection
	sender func(event string, payload interface{}) error
}
func (m *ModuleSupport) Init(info *model.Module) error {
	log := safeLog(m, info)
	if m == nil {
		return fmt.Errorf("assertion failed: receiver != nil")
	}
	m.Log = log
	if info == nil {
		return fmt.Errorf("invalid argument: info == nil")
	}
	if info.ID == "" {
		return fmt.Errorf("invalid argument: info.ID == \"\"")
	}
	m.Info = info
	conn, err := ninja.Connect(info.ID)
	m.Conn = conn
	return err
}
func (m *ModuleSupport) GetModuleInfo() *model.Module {
	return m.Info
}
func (m *ModuleSupport) SendEvent(event string, payload interface{}) error {
	err := failIfNotInitialized(m)
	if err == nil {
		if m.sender != nil {
			return m.sender(event, payload)
		} else {
			return fmt.Errorf("illegal state: module has not been exported")
		}
	} else {
		return err
	}
}
func (m *ModuleSupport) SetEventHandler(handler func(event string, payload interface{}) error) {
	m.sender = handler
}
func (m *ModuleSupport) SetLogLevel(level string) error {
	parsed, ok := loggo.ParseLevel(level)
	if ok && parsed != loggo.UNSPECIFIED {
		loggo.GetLogger("").SetLogLevel(parsed)
		safeLog(m, nil).Logf(parsed, "Log level has been reset to %s", level)
		return nil
	} else {
		return fmt.Errorf("%s is not a valid logging level")
	}
}
func failIfNotInitialized(m *ModuleSupport) error {
	if m == nil ||
		m.Info == nil ||
		m.Log == nil ||
		m.Conn == nil {
		return fmt.Errorf("illegal state: module has not been successfully initialized")
	} else {
		return nil
	}
}
func safeID(info *model.Module) string {
	if info == nil || info.ID == "" {
		return "{uninitialized-module-id}"
	} else {
		return info.ID
	}
}