Exemplo n.º 1
0
func newLogger() *logging.Logger {
	format := "%25s [%s] %8s: %s\n time,name,levelname,message"
	timeFormat := time.RFC3339
	level := logging.GetLevelValue(`INFO`)
	logger, _ := logging.WriterLogger("lazlo", level, format, timeFormat, os.Stdout, true)
	return logger
}
Exemplo n.º 2
0
Arquivo: config.go Projeto: thuvh/hal
func newLogger() *logging.Logger {
	format := "%25s [%s] %8s: %s\n time,name,levelname,message"
	timeFormat := time.RFC3339
	levelStr := strings.ToUpper(Config.LogLevel)
	level := logging.GetLevelValue(levelStr)
	logger, _ := logging.WriterLogger("hal", level, format, timeFormat, os.Stdout, true)
	return logger
}
Exemplo n.º 3
0
// NewBroker instantiates a new broker
func NewBroker() (*Broker, error) {

	broker := &Broker{
		MID:          0,
		Config:       newConfig(),
		Modules:      make(map[string]*Module),
		ApiResponses: make(map[int32]chan map[string]interface{}),
		cbIndex:      make(map[string]map[string]interface{}),
		WriteThread: &WriteThread{
			Chan:     make(chan Event),
			SyncChan: make(chan bool),
		},
		QuestionThread: &QuestionThread{
			userdex: make(map[string]QuestionQueue),
		},
		SigChan:  make(chan os.Signal),
		SyncChan: make(chan bool),
	}
	//correctly set the log level
	Logger.SetLevel(logging.GetLevelValue(strings.ToUpper(broker.Config.LogLevel)))

	broker.cbIndex[M] = make(map[string]interface{})
	broker.cbIndex[E] = make(map[string]interface{})
	broker.cbIndex[T] = make(map[string]interface{})
	broker.cbIndex[L] = make(map[string]interface{})
	broker.cbIndex[Q] = make(map[string]interface{})
	broker.WriteThread.broker = broker
	broker.QuestionThread.broker = broker

	//connect to slack and establish an RTM websocket
	socket, meta, err := broker.getASocket()
	if err != nil {
		return nil, err
	}
	broker.Socket = socket
	broker.SlackMeta = meta

	broker.Brain, err = broker.newBrain()
	if err != nil {
		return nil, err
	}
	//	broker.Brain = brain
	if err = broker.Brain.Open(); err != nil {
		Logger.Error(`couldn't open mah brain! `, err)
		return broker, err
	}
	return broker, nil
}