Ejemplo n.º 1
0
//NewClientOwnName creates a localClient or a RPC if a address is given and uses the given name as source
func NewClientOwnName(target, name string) (*Client, error) {
	if target == "" {
		//use local logger
		return NewLocalClient(), nil
	}
	logLocal := false
	logRPC := Outgoing.NewRPCInterface(target)
	if err := logRPC.Connect(); err != nil {
		fmt.Println(err)
		logLocal = true
	}

	var clientName string
	if name == "" {
		for name := range logRPC.Config.NameToCertificate {
			clientName = name
			break
		}
		if clientName == "" {
			var err error
			clientName, err = os.Hostname()
			if err != nil {
				return nil, err
			}
		}
	} else {
		clientName = name
	}
	err := logRPC.SendMessage(LogServer.NewDebugLogMessage(clientName, clientName+"-connected"))
	if err != nil {
		fmt.Println(err)
		logLocal = true
	}

	return &Client{logRPC: logRPC, name: clientName, localLogger: Local.GetLogger(), logLocal: logLocal}, nil
}
Ejemplo n.º 2
0
//NewLocalClient constructs a new client, which logs to stdout
func NewLocalClient() *Client {
	return &Client{localLogger: Local.GetLogger()}
}