本文整理汇总了Golang中log/syslog.NewLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLogger函数的具体用法?Golang NewLogger怎么用?Golang NewLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLogger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
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)
}
示例2: NewSysLogger
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
}
示例3: NewJobManager
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
}
示例4: getSysLogger
func getSysLogger() *log.Logger {
logger, err := syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)
if err != nil {
log.Fatal(err)
}
return logger
}
示例5: LoadConfig
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
}
示例6: main
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)
}
}
示例7: ToSyslog
// 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]
}
}
示例8: HttpServer
// 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
}
示例9: newSyslogger
func newSyslogger(p syslog.Priority) *log.Logger {
logger, err := syslog.NewLogger(p, 0)
if err != nil {
panic(err)
}
return logger
}
示例10: mustLog
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
}
示例11: initLogger
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)
}
}
示例12: init
func init() {
var err error
log.SetFlags(LOG_FLAGS)
Logger, err = syslog.NewLogger(LOG_PRIORITY, LOG_FLAGS)
if err != nil {
log.Fatal(err)
}
}
示例13: initLogger
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
}
}
示例14: NewRealLogger
func NewRealLogger() *RealLogger {
logger := log.New(os.Stdout, "", log.LstdFlags)
infoSysLogger, _ := syslog.NewLogger(syslog.LOG_INFO, log.LstdFlags)
return &RealLogger{
logger: logger,
infoSysLogger: infoSysLogger,
}
}
示例15: main
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)
}
}