Esempio n. 1
0
func main() {
	var config shuttle.ShuttleConfig
	var err error

	config.ParseFlags()

	if config.PrintVersion {
		fmt.Println(shuttle.VERSION)
		os.Exit(0)
	}

	if !config.UseStdin() {
		shuttle.ErrLogger.Fatalln("No stdin detected.")
	}

	if config.LogToSyslog {
		shuttle.Logger, err = syslog.NewLogger(syslog.LOG_INFO|syslog.LOG_SYSLOG, 0)
		if err != nil {
			log.Fatalf("Unable to setup syslog logger: %s\n", err)
		}
		shuttle.ErrLogger, err = syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_SYSLOG, 0)
		if err != nil {
			log.Fatalf("Unable to setup syslog error logger: %s\n", err)
		}
	}

	reader, deliverableBatches, programStats, batchWaiter, outletWaiter := MakeBasicBits(config)

	// Blocks until closed
	reader.Read(os.Stdin)

	// Shutdown everything else.
	Shutdown(reader.Outbox, programStats.Input, deliverableBatches, batchWaiter, outletWaiter)
}
Esempio n. 2
0
func NewSysLogger() *SysLogger {
	sl := &SysLogger{
		loggers: make(map[LogLevel]*log.Logger),
	}
	sl.loggers[DEBUG], _ = syslog.NewLogger(syslog.LOG_DEBUG, log.LstdFlags)
	sl.loggers[INFO], _ = syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)
	sl.loggers[WARN], _ = syslog.NewLogger(syslog.LOG_WARNING, log.LstdFlags)
	sl.loggers[ERROR], _ = syslog.NewLogger(syslog.LOG_ERR, log.LstdFlags)
	return sl
}
Esempio n. 3
0
func NewJobManager() (*JobManager, error) {
	var err error
	jm := JobManager{Shell: "/bin/sh"}
	Logger, err = syslog.NewLogger(syslog.LOG_NOTICE|syslog.LOG_CRON, 0)
	if err != nil {
		return nil, &JobberError{What: "Couldn't make Syslog logger.", Cause: err}
	}
	ErrLogger, err = syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_CRON, 0)
	if err != nil {
		return nil, &JobberError{What: "Couldn't make Syslog logger.", Cause: err}
	}
	jm.loadedJobs = false
	jm.jobRunner = NewJobRunnerThread()
	return &jm, nil
}
Esempio n. 4
0
func getSysLogger() *log.Logger {
	logger, err := syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)
	if err != nil {
		log.Fatal(err)
	}
	return logger
}
Esempio n. 5
0
func (c *sysLogger) LoadConfig(config map[string]interface{}) error {
	if level, ok := config["level"]; ok {
		c.level = level.(int)
	} else {
		c.level = LevelDebug
	}
	if sysLevel, ok := config["sysLevel"]; ok {
		c.sysLevel = LocalLevel[sysLevel.(int)]
	} else {
		c.sysLevel = syslog.LOG_LOCAL6
	}
	var Flags int
	if flags, ok := config["flags"]; ok {
		Flags = flags.(int)
	} else {
		Flags = 9
	}

	var err error
	c.logger, err = syslog.NewLogger(syslog.LOG_NOTICE|syslog.Priority(c.sysLevel), Flags)
	if err != nil {
		return errors.New("syslog newLogger error")
	}
	return nil
}
Esempio n. 6
0
func main() {

	mode = flag.String("m", "tcp", "portguard work mode: tcp or udp")
	debug = flag.Bool("d", false, "debug mode, print log to stderr")
	portCacheDuration = flag.Int64("duration", 120, "port cache duration")

	flag.Usage = usage
	flag.Parse()

	if *debug {
		mainLogger = log.New(io.Writer(os.Stderr), "", log.Ldate|log.Lmicroseconds)
	} else {
		var err error
		if mainLogger, err = syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_LOCAL7, log.Ldate|log.Lmicroseconds); err != nil {
			logMain(true, "open syslog failed:%s", err.Error())
		}
	}

	args := flag.Args()
	if len(args) > 0 {
		readConfigFile(args[0])
	}
	configGuard()
	configEcho()

	if *mode == "tcp" {
		tcpGuard()
	} else if *mode == "udp" {
		udpGuard()
	} else {
		fmt.Fprintf(os.Stderr, "don't support mode: %s\n", *mode)
	}
}
Esempio n. 7
0
// Send debug message to syslog facility
func ToSyslog() {
	syslogger, err := syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_USER, 0)
	if err == nil {
		debugLogger = syslogger
		prefixFormat = formatMap[false]
	}
}
Esempio n. 8
0
// Factory method for application
// Makes it possible to do integration testing.
func HttpServer() *echo.Echo {
	// Initialize global syslog logger
	if l, err := syslog.NewLogger(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, 0); err != nil {
		panic("gdo: failed to initialize syslog logger: " + err.Error())
	} else {
		logger = l
	}

	// Setup middleware
	e := echo.New()
	e.Use(middleware.RequestID)               // Put that first so loggers can log request id
	e.Use(em.Logger)                          // Log to console
	e.Use(middleware.HttpLogger(logger))      // Log to syslog
	e.Use(gdm.DOClientInitializer(*dumpFlag)) // Initialize DigitalOcean API client

	// Setup routes
	SetupDropletsRoutes(e.Group("/droplets"))
	SetupDropletActionsRoutes(e.Group("/droplets/:id/actions"))
	SetupImagesRoutes(e.Group("/images"))
	SetupImageActionsRoutes(e.Group("/images/:id/actions"))
	SetupActionsRoutes(e.Group("/actions"))
	SetupKeysRoutes(e.Group("/keys"))
	SetupRegionsRoutes(e.Group("/regions"))
	SetupSizesRoutes(e.Group("/sizes"))

	// We're done
	return e
}
Esempio n. 9
0
func newSyslogger(p syslog.Priority) *log.Logger {
	logger, err := syslog.NewLogger(p, 0)
	if err != nil {
		panic(err)
	}
	return logger
}
Esempio n. 10
0
func mustLog(p syslog.Priority) *log.Logger {
	p = p | syslog.LOG_DAEMON
	l, err := syslog.NewLogger(p, logFlags)
	if err != nil {
		panic("Failed to set up logger: " + err.Error())
	}
	return l
}
Esempio n. 11
0
File: surl.go Progetto: vosst/surl
func initLogger() *log.Logger {
	if configuration.LogToSyslog {
		l, _ := syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)
		return l
	} else {
		return log.New(os.Stdout, "surl ", log.LstdFlags)
	}
}
Esempio n. 12
0
func init() {
	var err error
	log.SetFlags(LOG_FLAGS)
	Logger, err = syslog.NewLogger(LOG_PRIORITY, LOG_FLAGS)
	if err != nil {
		log.Fatal(err)
	}

}
Esempio n. 13
0
func initLogger(slog bool) {
	if slog {
		l, err := syslog.NewLogger(syslog.LOG_INFO, 0)
		if err != nil {
			corelog.Fatalf("Can't initialize logger: %v", err)
		}
		log = l
	}
}
Esempio n. 14
0
func NewRealLogger() *RealLogger {
	logger := log.New(os.Stdout, "", log.LstdFlags)
	infoSysLogger, _ := syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)

	return &RealLogger{
		logger:        logger,
		infoSysLogger: infoSysLogger,
	}
}
Esempio n. 15
0
func main() {
	var (
		configFile string
		dry        bool
	)
	logger, err := syslog.NewLogger(syslog.LOG_INFO, stdlog.LstdFlags)
	if err != nil {
		stdlog.Fatal(err)
	}
	log.SetLogger(logger)
	flag.StringVar(&configFile, "config", "/etc/tsuru/tsuru.conf", "tsuru config file")
	flag.BoolVar(&dry, "dry", false, "dry-run: does not start the agent (for testing purposes)")
	flag.Parse()
	err = config.ReadConfigFile(configFile)
	if err != nil {
		fatal(err)
	}
	connString, err := config.GetString("database:url")
	if err != nil {
		fatal(err)
	}
	dbName, err := config.GetString("database:name")
	if err != nil {
		fatal(err)
	}
	db.Session, err = db.Open(connString, dbName)
	if err != nil {
		fatal(err)
	}
	defer db.Session.Close()
	fmt.Printf("Connected to MongoDB server at %s.\n", connString)
	fmt.Printf("Using the database %q.\n\n", dbName)

	if !dry {
		provisioner, err := config.GetString("provisioner")
		if err != nil {
			fmt.Printf("Warning: %q didn't declare a provisioner, using default provisioner.\n", configFile)
			provisioner = "juju"
		}
		app.Provisioner, err = provision.Get(provisioner)
		if err != nil {
			fatal(err)
		}
		fmt.Printf("Using %q provisioner.\n\n", provisioner)

		qServer, err := config.GetString("queue-server")
		if err != nil {
			fatal(err)
		}
		fmt.Printf("Connected to queue server at %s.\n", qServer)
		go handleMessages()
		ticker := time.Tick(time.Minute)
		fmt.Println("tsuru collector agent started...")
		jujuCollect(ticker)
	}
}
Esempio n. 16
0
func Logger(prefix string) *log.Logger {
	logger, err := syslog.NewLogger(syslog.LOG_NOTICE, log.Lshortfile)
	if err != nil {
		panic(err)
	}

	logger.SetPrefix("[" + prefix + "] ")

	return logger
}
Esempio n. 17
0
File: gopf.go Progetto: no2key/gopf
func init() {
	var err error
	logger, err = syslog.NewLogger(syslog.LOG_LOCAL0, 0)
	if err != nil {
		fmt.Printf("create logger failed:%s", err.Error())
		os.Exit(1)
	}
	logger.Println("are you lucky? go!")
	rand.Seed(time.Now().Unix())
}
Esempio n. 18
0
func initLogger() {
	if *useSyslog {
		var err error
		logger, err = syslog.NewLogger(syslog.LOG_NOTICE|syslog.LOG_DAEMON, log.LstdFlags|log.Lmicroseconds)
		panicOnError(err)
	}

	// Set log prefix to process ID to distinguish parent/child
	logger.SetPrefix(fmt.Sprintf("[%5d] ", os.Getpid()))
}
Esempio n. 19
0
// Init sets up the logging functionality
// TODO: Allow priority and type to by set in config
func (sh *SyslogHandler) Init() error {
	logger, err := syslog.NewLogger(syslog.LOG_ALERT|syslog.LOG_AUTH, 12)
	if err != nil {
		return fmt.Errorf("Unable to initialize syslog handler: %s", err)
	}

	logger.SetFlags(0)
	sh.logger = logger
	return nil
}
Esempio n. 20
0
func openSyslog(level Priority, prefix string) *log.Logger {
	logger, err := syslog.NewLogger(syslog.Priority(level), log.Lshortfile)
	if err != nil {
		fmt.Println("Error opening syslog: ", err)
		return nil
	}
	logger.SetPrefix(prefix)

	return logger
}
Esempio n. 21
0
func init() {
	var err error
	flag.Parse()
	l, err = syslog.NewLogger(syslog.LOG_USER|syslog.LOG_WARNING, 0)
	if err != nil {
		os.Exit(-1)
	}
	if *verbose {
		l.Printf("sending signal\n")
	}
}
Esempio n. 22
0
func newLogger(out *os.File, p syslog.Priority, prefix string) (*log.Logger, error) {
	if out == Syslog {
		l, err := syslog.NewLogger(p, log.LstdFlags)
		if err != nil {
			return nil, err
		}
		l.SetPrefix(prefix + " ")
		return l, nil
	}
	return log.New(out, fmt.Sprintf("[%s]%s ", priorityString[p], prefix), log.LstdFlags), nil
}
func main() {
	priority := syslog.LOG_LOCAL3 | syslog.LOG_NOTICE
	flags := log.Ldate | log.Lshortfile
	logger, err := syslog.NewLogger(priority, flags)
	if err != nil {
		fmt.Printf("Can't attach to syslog: %s", err)
		return
	}

	logger.Println("This is a test log message.")
}
Esempio n. 24
0
func main() {
	config, err := getConfig()
	if err != nil {
		errLogger.Fatalf("error=%q\n", err)
	}

	config.ID = version

	if !useStdin() {
		errLogger.Fatalln(`error="No stdin detected."`)
	}

	s := shuttle.NewShuttle(config)

	// Setup the loggers before doing anything else
	if logToSyslog {
		s.Logger, err = syslog.NewLogger(syslog.LOG_INFO|syslog.LOG_SYSLOG, 0)
		if err != nil {
			errLogger.Fatalf(`error="Unable to setup syslog logger: %s\n"`, err)
		}
		s.ErrLogger, err = syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_SYSLOG, 0)
		if err != nil {
			errLogger.Fatalf(`error="Unable to setup syslog error logger: %s\n"`, err)
		}
	} else {
		s.Logger = logger
		s.ErrLogger = errLogger
	}

	s.LoadReader(os.Stdin)

	s.Launch()

	go LogFmtMetricsEmitter(s.MetricsRegistry, config.StatsSource, config.StatsInterval, s.Logger)

	// blocks until the readers all exit
	s.WaitForReadersToFinish()

	// Shutdown the shuttle.
	s.Land()
}
Esempio n. 25
0
func NewShallowHAProxyLogRecord(out io.Writer, w http.ResponseWriter, r *http.Request) *HAProxyLogRecord {
	tlog, err := syslog.NewLogger(syslog.LOG_LOCAL5|syslog.LOG_INFO, 0)
	//if cannot connect to syslog just get basic logger to stdout
	if err != nil {
		tlog = log.New(os.Stdout, "", 0)
	}
	return &HAProxyLogRecord{
		ResponseWriter: w,
		Request:        r,
		sLog:           tlog,
	}
}
Esempio n. 26
0
func init() {
	flag.BoolVar(&forceUpdate, "f", false, "update noip even if IP hasn't changed")
	flag.BoolVar(&addHost, "a", false, "print config with added host to stdout")
	flag.Parse()

	if addHost {
		infoLog = log.New(os.Stdout, "", 0)
		errLog = log.New(os.Stdout, "", 0)
	} else {
		var err error
		infoLog, err = syslog.NewLogger(syslog.LOG_INFO, 0)
		checkErr(err)
		errLog, err = syslog.NewLogger(syslog.LOG_ERR, 0)
		checkErr(err)
	}

	err := readConfig()
	if addHost && os.IsNotExist(err) {
		return
	}
	checkErr(err)
}
Esempio n. 27
0
func main() {
	// Create a new syslog container to send to notice/local0
	// and include the file shortname
	// Setup to log to notice/local0
	// Log using file short name
	s, err := syslog.NewLogger(syslog.LOG_NOTICE|syslog.LOG_LOCAL0, log.Lshortfile)
	if err != nil {
		panic(err)
	}

	// Log "GOTUTORIAL" message
	s.Println("GOTUTORIAL")
}
Esempio n. 28
0
File: log.go Progetto: wor/goanysync
// New creates a new Log and returns pointer to it.
func New(prefix string, sp syslog.Priority, cp syslog.Priority) (*Log, error) {
	l := new(Log)
	consoleFlags := log.Ldate | log.Ltime | log.Lshortfile
	l.conlog1 = log.New(os.Stdout, prefix+": ", consoleFlags)
	l.conlog2 = log.New(os.Stderr, prefix+": ", consoleFlags)
	l.sp = sp
	l.cp = cp

	var err error
	if l.syslog, err = syslog.NewLogger(syslog.LOG_INFO, log.Lshortfile); err != nil {
		return nil, err
	}
	return l, nil
}
Esempio n. 29
0
func NewSysLogger(level int) (result *DefaultLogger, err error) {
	result = &DefaultLogger{}
	priorities := []syslog.Priority{syslog.LOG_CRIT, syslog.LOG_ERR, syslog.LOG_WARNING, syslog.LOG_INFO, syslog.LOG_DEBUG}
	loggers := []**log.Logger{&result.CriticalLogger, &result.ErrorLogger, &result.WarningLogger, &result.InfoLogger, &result.DebugLogger}
	for index, logger := range loggers {
		if level >= index {
			*logger, err = syslog.NewLogger(priorities[index], 0)
			if err != nil {
				return
			}
		}
	}
	return
}
Esempio n. 30
0
// StartLogger initializes the log file.
func StartLogger() {
	var err error

	if BOOT {
		if logFile, err = os.OpenFile(_LOG_FILE, os.O_WRONLY|os.O_TRUNC, 0); err != nil {
			log.Print(err)
		} else {
			Log = log.New(logFile, "", log.Lshortfile)
		}
	} else {
		if Log, err = syslog.NewLogger(syslog.LOG_NOTICE, log.Lshortfile); err != nil {
			log.Fatal(err)
		}
	}
}