func (logDB *LoggerDB) Log(logType string, data []byte, environment, uuid string, debug bool) {
	if debug {
		log.Printf("Sending %d bytes to DB for %s - %s", len(data), environment, uuid)
	}
	switch logType {
	case types.StatusLog:
		logDB.Status(data, environment, uuid, debug)
	case types.ResultLog:
		logDB.Result(data, environment, uuid, debug)
	}
}
Log - Function that sends JSON result/status/query logs to the configured DB
package logging
import (
	"encoding/json"
	"fmt"
	"log"
	"strings"
	"time"
	"github.com/jinzhu/gorm"
	"github.com/jmpsec/osctrl/backend"
	"github.com/jmpsec/osctrl/queries"
	"github.com/jmpsec/osctrl/settings"
	"github.com/jmpsec/osctrl/types"
)
const (
	defaultCleanupInterval = 86400
)
type OsqueryResultData struct {
	gorm.Model
	UUID        string `gorm:"index"`
	Environment string
	Name        string
	Action      string
	Epoch       int64
	Columns     []byte
	Counter     int
}
type OsqueryStatusData struct {
	gorm.Model
	UUID        string `gorm:"index"`
	Environment string
	Line        string
	Message     string
	Version     string
	Filename    string
	Severity    string
}
type OsqueryQueryData struct {
	gorm.Model
	UUID        string `gorm:"index"`
	Environment string
	Name        string
	Data        []byte
	Status      int
}
type LoggerDB struct {
	Database      *gorm.DB
	Configuration backend.JSONConfigurationDB
	Enabled       bool
}
func CreateLoggerDB(dbfile, dbname string) (*LoggerDB, error) {
	config, err := backend.LoadConfiguration(dbfile, dbname)
	if err != nil {
		return nil, err
	}
	database, err := backend.GetDB(config)
	if err != nil {
		return nil, err
	}
	l := &LoggerDB{
		Database:      database,
		Configuration: config,
		Enabled:       true,
	}
	if err := database.AutoMigrate(OsqueryStatusData{}).Error; err != nil {
		log.Fatalf("Failed to AutoMigrate table (osquery_status_data): %v", err)
	}
	if err := database.AutoMigrate(OsqueryResultData{}).Error; err != nil {
		log.Fatalf("Failed to AutoMigrate table (osquery_result_data): %v", err)
	}
	if err := database.AutoMigrate(OsqueryQueryData{}).Error; err != nil {
		log.Fatalf("Failed to AutoMigrate table (osquery_query_data): %v", err)
	}
	return l, nil
}
func (logDB *LoggerDB) Settings(mgr *settings.Settings) {
	log.Printf("Setting DB logging settings\n")
	if !mgr.IsValue(settings.ServiceAdmin, settings.QueryResultLink) {
		if err := mgr.NewStringValue(settings.ServiceAdmin, settings.QueryResultLink, settings.QueryLink); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.QueryResultLink, err)
		}
	}
	if !mgr.IsValue(settings.ServiceAdmin, settings.StatusLogsLink) {
		if err := mgr.NewStringValue(settings.ServiceAdmin, settings.StatusLogsLink, settings.StatusLink); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.StatusLogsLink, err)
		}
	}
	if !mgr.IsValue(settings.ServiceAdmin, settings.ResultLogsLink) {
		if err := mgr.NewStringValue(settings.ServiceAdmin, settings.ResultLogsLink, settings.ResultsLink); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.ResultLogsLink, err)
		}
	}
	if !mgr.IsValue(settings.ServiceAdmin, settings.CleanStatusLogs) {
		if err := mgr.NewBooleanValue(settings.ServiceAdmin, settings.CleanStatusLogs, false); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.CleanStatusLogs, err)
		}
	}
	if !mgr.IsValue(settings.ServiceAdmin, settings.CleanStatusInterval) {
		if err := mgr.NewIntegerValue(settings.ServiceAdmin, settings.CleanStatusInterval, defaultCleanupInterval); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.CleanStatusInterval, err)
		}
	}
	if !mgr.IsValue(settings.ServiceAdmin, settings.CleanResultLogs) {
		if err := mgr.NewBooleanValue(settings.ServiceAdmin, settings.CleanResultLogs, false); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.CleanResultLogs, err)
		}
	}
	if !mgr.IsValue(settings.ServiceAdmin, settings.CleanResultInterval) {
		if err := mgr.NewIntegerValue(settings.ServiceAdmin, settings.CleanResultInterval, defaultCleanupInterval); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.CleanResultInterval, err)
		}
	}
	if !mgr.IsValue(settings.ServiceAdmin, settings.CleanQueryLogs) {
		if err := mgr.NewBooleanValue(settings.ServiceAdmin, settings.CleanQueryLogs, false); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.CleanQueryLogs, err)
		}
	}
	if !mgr.IsValue(settings.ServiceAdmin, settings.CleanQueryEntries) {
		if err := mgr.NewIntegerValue(settings.ServiceAdmin, settings.CleanQueryEntries, 100); err != nil {
			log.Fatalf("Failed to add %s to settings: %v", settings.CleanQueryEntries, err)
		}
	}
}