// createLogStream creates a log stream for the instance of the awslogs logging driver
776237
func (l *logStream) createLogStream() error {
	input := &cloudwatchlogs.CreateLogStreamInput{
		LogGroupName:  aws.String(l.logGroupName),
		LogStreamName: aws.String(l.logStreamName),
	}

	_, err := l.client.CreateLogStream(input)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			fields := logrus.Fields{
				"errorCode":     awsErr.Code(),
				"message":       awsErr.Message(),
				"origError":     awsErr.OrigErr(),
				"logGroupName":  l.logGroupName,
				"logStreamName": l.logStreamName,
			}
			if awsErr.Code() == resourceAlreadyExistsCode {
				// Allow creation to succeed
				logrus.WithFields(fields).Info("Log stream already exists")
				return nil
			}
			logrus.WithFields(fields).Error("Failed to create log stream")
		}
	}
	return err
}
1256312
func (s *FilteredLogEvent) SetLogStreamName(v string) *FilteredLogEvent {
	s.LogStreamName = &v
	return s
}
608278
func streamsFromAnnotatedLog(ctx context.Context, log string) (*rawpresentation.Streams, error) {
	c := &memoryClient{}
	p := annotee.New(ctx, annotee.Options{
		Client:                 c,
		MetadataUpdateInterval: -1, // Neverrrrrr send incr updates.
		Offline:                true,
	})

	is := annotee.Stream{
		Reader:           bytes.NewBufferString(log),
		Name:             types.StreamName("stdout"),
		Annotate:         true,
		StripAnnotations: true,
	}
	// If this ever has more than one stream then memoryClient needs to become
	// goroutine safe
	if err := p.RunStreams([]*annotee.Stream{&is}); err != nil {
		return nil, err
	}
	p.Finish()
	return c.ToLogDogStreams()
}
1123427
func MakePlainFileLogger(filePath string) (Sender, error) {
	s := &nativeLogger{Base: NewBase("")}

	if err := s.SetFormatter(MakeDefaultFormatter()); err != nil {
		return nil, err
	}

	f, err := os.OpenFile(filePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		return nil, fmt.Errorf("error opening logging file, %s", err.Error())
	}

	s.level = LevelInfo{level.Trace, level.Trace}

	fallback := log.New(os.Stderr, "", log.LstdFlags)
	_ = s.SetErrorHandler(ErrorHandlerFromLogger(fallback))

	s.reset = func() {
		s.logger = log.New(f, "", 0)
	}

	s.closer = func() error {
		return f.Close()
	}

	return s, nil
}
834368
func (c *Client) CreateSyslog(i *CreateSyslogInput) (*Syslog, error) {
	if i.Service == "" {
		return nil, ErrMissingService
	}

	if i.Version == 0 {
		return nil, ErrMissingVersion
	}

	path := fmt.Sprintf("/service/%s/version/%d/logging/syslog", i.Service, i.Version)
	resp, err := c.PostForm(path, i, nil)
	if err != nil {
		return nil, err
	}

	var s *Syslog
	if err := decodeJSON(&s, resp.Body); err != nil {
		return nil, err
	}
	return s, nil
}
1328112
func CreateLogger(args ...interface{}) (Logger, error) {
	config := Config{}
	logger := Logger{}
	r := regexp.MustCompile(`bunyan.Config$`)

	if len(args) == 0 {
		return logger, fmt.Errorf("Create logger requires either a bunyan.Config or String argument")
	}

	// get hostname
	if hostname, err := os.Hostname(); err != nil {
		return logger, err
	} else {
		logger.hostname = hostname
	}

	arg := args[0]
	argType := typeName(arg)

	if argType == "string" {
		config.Name = arg.(string)
	} else if r.MatchString(argType) {
		config = arg.(Config)
		if config.Name == "" {
			return logger, fmt.Errorf("Bunyan Config requires a name, none specified")
		}
	} else {
		return logger, fmt.Errorf("Create logger requires either a bunyan.Config or String argument")
	}

	// add the config to the logger
	logger.config = config
	logger.staticFields = config.StaticFields
	logger.serializers = config.Serializers

	// add the streams
	if len(config.Streams) != 0 {
		for _, stream := range config.Streams {
			logger.AddStream(stream)
		}
	} else if config.Stream != nil {
		simpleStream := Stream{Stream: config.Stream, Name: config.Name}
		logger.AddStream(simpleStream)
	}

	return logger, nil
}
644387
func (s *LastCrawlInfo) SetLogStream(v string) *LastCrawlInfo {
	s.LogStream = &v
	return s
}
1194570
func NewLog(out io.Writer) *Log {
	d := new(Log)
	d.Logger = log.New(out, "[ORM]", 1e9)
	return d
}
769210
func (c *client) LogStream(id int64) (StreamWriter, error) {
	rawurl := fmt.Sprintf(pathLogsAuth, c.base, id, c.token)
	uri, err := url.Parse(rawurl)
	if err != nil {
		return nil, err
	}
	if uri.Scheme == "https" {
		uri.Scheme = "wss"
	} else {
		uri.Scheme = "ws"
	}

	// TODO need TLS client configuration

	conn, _, err := websocket.DefaultDialer.Dial(uri.String(), nil)
	return conn, err
}
1368364
func (g *Group) Create(stream string) (io.Writer, error) {
	if _, err := g.client.CreateLogStream(&cloudwatchlogs.CreateLogStreamInput{
		LogGroupName:  &g.group,
		LogStreamName: &stream,
	}); err != nil {
		return nil, err
	}

	return NewWriter(g.group, stream, g.client), nil
}
1374549
func NewStreamLogger(name string, ws WriteStringer, l LevelInfo) (Sender, error) {
	return setup(MakeStreamLogger(ws), name, l)
}
1130379
func NewLogWatcher() *LogWatcher {
	return &LogWatcher{
		Msg:          make(chan *Message, logWatcherBufferSize),
		Err:          make(chan error, 1),
		producerGone: make(chan struct{}),
		consumerGone: make(chan struct{}),
	}
}
323432
func (s *GetLogEventsInput) SetLogStreamName(v string) *GetLogEventsInput {
	s.LogStreamName = &v
	return s
}
157528
func (c *Client) OpenLogTransferStream(modelUUID string) (base.Stream, error) {
	attrs := url.Values{}
	attrs.Set("jujuclientversion", jujuversion.Current.String())
	headers := http.Header{}
	headers.Set(params.MigrationModelHTTPHeader, modelUUID)
	caller := c.caller.RawAPICaller()
	stream, err := caller.ConnectControllerStream("/migrate/logtransfer", attrs, headers)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return stream, nil
}
1269952
func (z *ZipFile) CreateWriter(name string, w io.Writer) error {
	z.Writer = zip.NewWriter(w)
	z.Name = name
	return nil
}
215175
func (l *Logger) AddStream(stream Stream) error {
	if err := stream.init(l.config); err != nil {
		return err
	}
	l.streams = append(l.streams, stream)
	return nil
}
1034935
func createCustomizedLogger(name string, level Level, format string, timeFormat string, out io.Writer, sync bool, queueSize int, requestSize int, bufferSize int, timeInterval time.Duration) (*Logger, error) {
	logger := new(Logger)

	err := logger.parseFormat(format)
	if err != nil {
		return nil, err
	}

	// assign values to logger
	logger.name = name
	logger.level = level
	logger.out = out
	logger.seqid = 0
	logger.sync = sync
	logger.queue = make(chan string, queueSize)
	logger.request = make(chan request, requestSize)
	logger.flush = make(chan bool)
	logger.finish = make(chan bool)
	logger.quit = make(chan bool)
	logger.startTime = time.Now()
	logger.fd = nil
	logger.timeFormat = timeFormat
	logger.bufferSize = bufferSize
	logger.timeInterval = timeInterval

	// start watcher to write logs if it is async or no runtime field
	if !logger.sync {
		go logger.watcher()
	}

	return logger, nil
}