当前位置: 首页>>代码示例>>Golang>>正文


Golang journal.Enabled函数代码示例

本文整理汇总了Golang中github.com/coreos/go-systemd/journal.Enabled函数的典型用法代码示例。如果您正苦于以下问题:Golang Enabled函数的具体用法?Golang Enabled怎么用?Golang Enabled使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Enabled函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Log

func (sink *tryJournalSink) Log(fields Fields) {
	if journal.Enabled() {
		sink.j.Log(fields)
	} else {
		sink.w.Log(fields)
	}
}
开发者ID:rjocoleman,项目名称:etcdctl,代码行数:7,代码来源:sinks.go

示例2: New

// New creates a journald logger using the configuration passed in on
// the context.
func New(ctx logger.Context) (logger.Logger, error) {
	if !journal.Enabled() {
		return nil, fmt.Errorf("journald is not enabled on this host")
	}
	// Strip a leading slash so that people can search for
	// CONTAINER_NAME=foo rather than CONTAINER_NAME=/foo.
	name := ctx.ContainerName
	if name[0] == '/' {
		name = name[1:]
	}

	// parse log tag
	tag, err := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate)
	if err != nil {
		return nil, err
	}

	vars := map[string]string{
		"CONTAINER_ID":      ctx.ContainerID[:12],
		"CONTAINER_ID_FULL": ctx.ContainerID,
		"CONTAINER_NAME":    name,
		"CONTAINER_TAG":     tag,
	}
	extraAttrs := ctx.ExtraAttributes(sanitizeKeyMod)
	for k, v := range extraAttrs {
		vars[k] = v
	}
	return &journald{vars: vars, readers: readerList{readers: make(map[*logger.LogWatcher]*logger.LogWatcher)}}, nil
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:31,代码来源:journald.go

示例3: init

func init() {
	sinks := make([]Sink, 0)
	sinks = append(sinks, WriterSink(os.Stdout, BasicFormat, BasicFields))
	if journal.Enabled() {
		sinks = append(sinks, JournalSink())
	}
	defaultLogger = NewSimple(sinks...)
}
开发者ID:rjocoleman,项目名称:etcdctl,代码行数:8,代码来源:logger.go

示例4: CombinedSink

func CombinedSink(writer io.Writer, format string, fields []string) Sink {
	sinks := make([]Sink, 0)
	sinks = append(sinks, WriterSink(writer, format, fields))
	if journal.Enabled() {
		sinks = append(sinks, JournalSink())
	}

	return &combinedSink{
		sinks: sinks,
	}
}
开发者ID:rwindelz,项目名称:go-log,代码行数:11,代码来源:sinks_unix.go

示例5: New

func New(id string, name string) (logger.Logger, error) {
	if !journal.Enabled() {
		return nil, fmt.Errorf("journald is not enabled on this host")
	}
	// Strip a leading slash so that people can search for
	// CONTAINER_NAME=foo rather than CONTAINER_NAME=/foo.
	if name[0] == '/' {
		name = name[1:]
	}
	jmap := map[string]string{
		"CONTAINER_ID":      id[:12],
		"CONTAINER_ID_FULL": id,
		"CONTAINER_NAME":    name}
	return &Journald{Jmap: jmap}, nil
}
开发者ID:pbx0,项目名称:docker,代码行数:15,代码来源:journald.go

示例6: New

// New creates a journald logger using the configuration passed in on
// the context.
func New(ctx logger.Context) (logger.Logger, error) {
	if !journal.Enabled() {
		return nil, fmt.Errorf("journald is not enabled on this host")
	}
	// Strip a leading slash so that people can search for
	// CONTAINER_NAME=foo rather than CONTAINER_NAME=/foo.
	name := ctx.ContainerName
	if name[0] == '/' {
		name = name[1:]
	}
	jmap := map[string]string{
		"CONTAINER_ID":      ctx.ContainerID[:12],
		"CONTAINER_ID_FULL": ctx.ContainerID,
		"CONTAINER_NAME":    name}
	return &journald{Jmap: jmap}, nil
}
开发者ID:ch3lo,项目名称:docker,代码行数:18,代码来源:journald.go

示例7: New

// New creates a journald logger using the configuration passed in on
// the context.
func New(ctx logger.Context) (logger.Logger, error) {
	if !journal.Enabled() {
		return nil, fmt.Errorf("journald is not enabled on this host")
	}
	// Strip a leading slash so that people can search for
	// CONTAINER_NAME=foo rather than CONTAINER_NAME=/foo.
	name := ctx.ContainerName
	if name[0] == '/' {
		name = name[1:]
	}

	vars := map[string]string{
		"CONTAINER_ID":      ctx.ContainerID[:12],
		"CONTAINER_ID_FULL": ctx.ContainerID,
		"CONTAINER_NAME":    name,
	}
	extraAttrs := ctx.ExtraAttributes(strings.ToTitle)
	for k, v := range extraAttrs {
		vars[k] = v
	}
	return &journald{vars: vars, readers: readerList{readers: make(map[*logger.LogWatcher]*logger.LogWatcher)}}, nil
}
开发者ID:RickyCook,项目名称:docker,代码行数:24,代码来源:journald.go

示例8: New

// New creates a journald logger using the configuration passed in on
// the context.
func New(ctx logger.Context) (logger.Logger, error) {
	if !journal.Enabled() {
		return nil, fmt.Errorf("journald is not enabled on this host")
	}

	// parse log tag
	tag, err := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate)
	if err != nil {
		return nil, err
	}

	vars := map[string]string{
		"CONTAINER_ID":      ctx.ContainerID[:12],
		"CONTAINER_ID_FULL": ctx.ContainerID,
		"CONTAINER_NAME":    ctx.Name(),
		"CONTAINER_TAG":     tag,
	}
	extraAttrs := ctx.ExtraAttributes(sanitizeKeyMod)
	for k, v := range extraAttrs {
		vars[k] = v
	}
	return &journald{vars: vars, readers: readerList{readers: make(map[*logger.LogWatcher]*logger.LogWatcher)}}, nil
}
开发者ID:harche,项目名称:docker,代码行数:25,代码来源:journald.go

示例9: NewJournaldFormatter

func NewJournaldFormatter() (Formatter, error) {
	if !journal.Enabled() {
		return nil, errors.New("No systemd detected")
	}
	return &journaldFormatter{}, nil
}
开发者ID:johnmccawley,项目名称:origin,代码行数:6,代码来源:journald_formatter.go

示例10: NewJournalLogger

func NewJournalLogger() (Logger, error) {
	if !journal.Enabled() {
		return nil, errors.New("could not connect to journald socket")
	}
	return &jlogger{}, nil
}
开发者ID:bvandre,项目名称:bvlog,代码行数:6,代码来源:journal.go

示例11: connector

func connector(context *cli.Context) int {
	config, configFilename, err := lib.GetConfig(context)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to read config file: %s", err)
		return 1
	}

	logToJournal := config.LogToJournal && journal.Enabled()
	logToConsole := context.Bool("log-to-console")

	if logToJournal {
		log.SetJournalEnabled(true)
		if logToConsole {
			log.SetWriter(os.Stderr)
		} else {
			log.SetWriter(ioutil.Discard)
		}
	} else {
		logFileMaxBytes := config.LogFileMaxMegabytes * 1024 * 1024
		var logWriter io.Writer
		logWriter, err = log.NewLogRoller(config.LogFileName, logFileMaxBytes, config.LogMaxFiles)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to start log roller: %s", err)
			return 1
		}

		if logToConsole {
			logWriter = io.MultiWriter(logWriter, os.Stderr)
		}
		log.SetWriter(logWriter)
	}

	logLevel, ok := log.LevelFromString(config.LogLevel)
	if !ok {
		fmt.Fprintf(os.Stderr, "Log level %s is not recognized", config.LogLevel)
		return 1
	}
	log.SetLevel(logLevel)

	if configFilename == "" {
		log.Info("No config file was found, so using defaults")
	}

	log.Info(lib.FullName)
	fmt.Println(lib.FullName)

	if !config.CloudPrintingEnable && !config.LocalPrintingEnable {
		log.Fatal("Cannot run connector with both local_printing_enable and cloud_printing_enable set to false")
		return 1
	}

	if _, err := os.Stat(config.MonitorSocketFilename); !os.IsNotExist(err) {
		if err != nil {
			log.Fatalf("Failed to stat monitor socket: %s", err)
		} else {
			log.Fatalf(
				"A connector is already running, or the monitoring socket %s wasn't cleaned up properly",
				config.MonitorSocketFilename)
		}
		return 1
	}

	jobs := make(chan *lib.Job, 10)
	xmppNotifications := make(chan xmpp.PrinterNotification, 5)

	var g *gcp.GoogleCloudPrint
	var x *xmpp.XMPP
	if config.CloudPrintingEnable {
		xmppPingTimeout, err := time.ParseDuration(config.XMPPPingTimeout)
		if err != nil {
			log.Fatalf("Failed to parse xmpp ping timeout: %s", err)
			return 1
		}
		xmppPingInterval, err := time.ParseDuration(config.XMPPPingInterval)
		if err != nil {
			log.Fatalf("Failed to parse xmpp ping interval default: %s", err)
			return 1
		}

		g, err = gcp.NewGoogleCloudPrint(config.GCPBaseURL, config.RobotRefreshToken,
			config.UserRefreshToken, config.ProxyName, config.GCPOAuthClientID,
			config.GCPOAuthClientSecret, config.GCPOAuthAuthURL, config.GCPOAuthTokenURL,
			config.GCPMaxConcurrentDownloads, jobs)
		if err != nil {
			log.Fatal(err)
			return 1
		}

		x, err = xmpp.NewXMPP(config.XMPPJID, config.ProxyName, config.XMPPServer, config.XMPPPort,
			xmppPingTimeout, xmppPingInterval, g.GetRobotAccessToken, xmppNotifications)
		if err != nil {
			log.Fatal(err)
			return 1
		}
		defer x.Quit()
	}

	cupsConnectTimeout, err := time.ParseDuration(config.CUPSConnectTimeout)
	if err != nil {
		log.Fatalf("Failed to parse CUPS connect timeout: %s", err)
//.........这里部分代码省略.........
开发者ID:tokarlss,项目名称:cups-connector,代码行数:101,代码来源:gcp-cups-connector.go

示例12: NewLogger

func NewLogger() Logger {
	if !debug && journal.Enabled() {
		return &JournaldLogger{}
	}
	return &StdErrLogger{}
}
开发者ID:jawi,项目名称:mad,代码行数:6,代码来源:srv_linux.go


注:本文中的github.com/coreos/go-systemd/journal.Enabled函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。