// NewMariaDBBinlogFormat returns a typical BinlogFormat for MariaDB 10.0.
500928
func NewMariaDBBinlogFormat() BinlogFormat {
	return BinlogFormat{
		FormatVersion:     4,
		ServerVersion:     "10.0.13-MariaDB-1~precise-log",
		HeaderLength:      19,
		ChecksumAlgorithm: BinlogChecksumAlgOff,
		// HeaderSizes is very long because the MariaDB specific events are indexed at 160+
		HeaderSizes: []byte{
			56, 13, 0, 8, 0, 18, 0, 4, 4, 4,
			4, 18, 0, 0, 220, 0, 4, 26, 8, 0,
			0, 0, 8, 8, 8, 2, 0, 0, 0, 10,
			10, 10, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			4, 19, 4},
	}
}
1109680
func NewLogForwarder(args OpenLogForwarderArgs) (*LogForwarder, error) {
	lf := &LogForwarder{
		args:      args,
		enabledCh: make(chan bool, 1),
	}
	err := catacomb.Invoke(catacomb.Plan{
		Site: &lf.catacomb,
		Work: func() error {
			return errors.Trace(lf.loop())
		},
	})
	if err != nil {
		return nil, errors.Trace(err)
	}
	return lf, nil
}
431913
func newNodeDB(path string, version int, self NodeID) (*nodeDB, error) {
	if path == "" {
		return newMemoryNodeDB(self)
	}
	return newPersistentNodeDB(path, version, self)
}
163808
func NewLogFromEntry(le LogEntry) Log {
	keyLen := len(le.Key)
	valLen := len(le.Value)
	kvLen := keyLen + valLen + 8
	l := make([]byte, logEntryHeaderLen+kvLen)

	encoding.PutUint64(l[tsPos:attrPos], le.Timestamp)

	l[attrPos] = le.ModeOpToByte()

	kvPosition := logEntryHeaderLen + 4
	encoding.PutUint32(l[logEntryHeaderLen:kvPosition], uint32(keyLen))
	copy(l[kvPosition:kvPosition+keyLen], le.Key)

	encoding.PutUint32(l[kvPosition+keyLen:kvPosition+keyLen+4], uint32(valLen))
	copy(l[kvPosition+keyLen+4:], le.Value)

	encoding.PutUint32(l[sizePos:tsPos], uint32(kvLen))
	return l
}
614714
func NewLogHelper(v ...interface{}) (*LogHelper, error) {
	mask := os.O_APPEND | os.O_RDWR | os.O_CREATE
	mylog := LogHelper{}

	// use stdout & stderr
	if len(v) == 0 {
		mylog.Logger[0] = log.New(os.Stdout, "TRACE - ", FLAGS)
		mylog.Logger[1] = log.New(os.Stderr, "ERROR - ", FLAGS)
		return &mylog, nil
	}
	fileName := v[0].(string)
	// app.log & app.log.error
	mylog.LogFileNames = [2]string{fileName, fileName + ".error"}
	// check dir wether exist and mkdir
	if _, err := os.Stat(path.Dir(mylog.LogFileNames[0])); err != nil {
		os.Mkdir(path.Dir(mylog.LogFileNames[0]), 0777)
	}

	if logFile, err := os.OpenFile(mylog.LogFileNames[0], mask, 0666); err == nil {
		mylog.Logger[0] = log.New(logFile, "TRACE - ", FLAGS)
		mylog.Logger[0].Flags()
	} else {
		return nil, err
	}

	if logFile, err := os.OpenFile(mylog.LogFileNames[1], mask, 0666); err == nil {
		mylog.Logger[1] = log.New(logFile, "ERROR - ", FLAGS)
	} else {
		return nil, err
	}
	return &mylog, nil
}
1139785
func NewDeleteRowsEvent(f BinlogFormat, s *FakeBinlogStream, tableID uint64, rows Rows) BinlogEvent {
	return newRowsEvent(f, s, eDeleteRowsEventV2, tableID, rows)
}
448962
func (ev mariadbBinlogEvent) GTID(f BinlogFormat) (GTID, bool, error) {
	const FLStandalone = 1

	data := ev.Bytes()[f.HeaderLength:]
	flags2 := data[8+4]

	return MariadbGTID{
		Sequence: binary.LittleEndian.Uint64(data[:8]),
		Domain:   binary.LittleEndian.Uint32(data[8 : 8+4]),
		Server:   ev.ServerID(),
	}, flags2&FLStandalone == 0, nil
}
447201
func NewLoggerFromLoggingConfig(loggingConfig *logconfig.LoggingConfig) (*logging.Logger, error) {
	if loggingConfig == nil {
		return NewStdErrLogger()
	} else {
		outputLogger, errCh, err := loggerFromLoggingConfig(loggingConfig)
		if err != nil {
			return nil, err
		}
		logger := logging.NewLogger(outputLogger)
		if !loggingConfig.Trace {
			logger.Trace = log.NewNopLogger()
		}
		go func() {
			err := <-errCh.Out()
			if err != nil {
				fmt.Printf("Logging error: %v", err)
			}
		}()
		return logger, nil
	}
}
305690
func NewFileLogger(f string, o, mode, maxLines, maxRotate, bufsize int) (*FileLogger, error) {
	var file *os.File
	var err error

	switch mode {
	case APPEND:
		// open log file, append if it already exists
		file, err = os.OpenFile(f, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
	case TRUNC:
		// just truncate file and start logging
		file, err = os.OpenFile(f, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
	case BACKUP:
		// rotate every time a new logger is created
		file, err = openBackup(f, 0, maxRotate)
	case ROTATE:
		// "normal" rotation, when file reaches line limit
		file, err = openBackup(f, maxLines, maxRotate)
	default:
		return nil, fmt.Errorf("Invalid mode parameter: %d", mode)
	}
	if err != nil {
		return nil, fmt.Errorf("Error creating logger: %s", err)
	}

	return newFileLogger(file, o, mode, maxLines, maxRotate, bufsize), nil
}
314161
func NewLogEntryDecoder(r io.Reader) LogEntryDecoder {
	return &logEntryDecoder{
		lenBuf: make([]byte, binaryEncodeLen),
		buf:    make([]byte, 1024),
		r:      r,
	}
}
1258883
func NewLogRecord(
	name string,
	level LogLevelType,
	pathName string,
	fileName string,
	lineNo uint32,
	funcName string,
	format string,
	useFormat bool,
	args []interface{}) *LogRecord {

	return &LogRecord{
		CreatedTime: time.Now(),
		Name:        name,
		Level:       level,
		PathName:    pathName,
		FileName:    fileName,
		LineNo:      lineNo,
		FuncName:    funcName,
		Format:      format,
		UseFormat:   useFormat,
		Args:        args,
		Message:     "",
	}
}
1370074
func NewLog(m message.Composer) *Log {
	l := &Log{
		Level:     convertFromPriority(m.Priority()),
		Timestamp: time.Now(),
		msg:       m,
	}
	l.appendCallerInfo(2)
	return l
}
1101264
func newBytesBinParser(b []byte) *binParser {
	p := &binParser{bufio.NewReader(bytes.NewReader(b)), 0, 0}
	if p.r == nil {
		return nil
	}
	return p
}
283530
func NewAppLog(loggerName string, msg []byte) *AppLog {
	now := time.Now().UTC()
	return &AppLog{
		Timestamp:  now.UnixNano(),
		Time:       now.Format(time.RFC3339),
		Type:       "app.log",
		Logger:     loggerName,
		Hostname:   hostname,
		EnvVersion: "2.0",
		Pid:        os.Getpid(),
		Fields: map[string]interface{}{
			"msg": string(bytes.TrimSpace(msg)),
		},
	}
}
1242962
func NewLogTailer(st LogTailerState, params LogTailerParams) (LogTailer, error) {
	session := st.MongoSession().Copy()
	t := &logTailer{
		modelUUID:       st.ModelUUID(),
		session:         session,
		logsColl:        session.DB(logsDB).C(logCollectionName(st.ModelUUID())).With(session),
		params:          params,
		logCh:           make(chan *LogRecord),
		recentIds:       newRecentIdTracker(maxRecentLogIds),
		maxInitialLines: maxInitialLines,
	}
	t.tomb.Go(func() error {
		defer close(t.logCh)
		defer session.Close()
		err := t.loop()
		return errors.Cause(err)
	})
	return t, nil
}
1292759
func NewLoggerExt(component string, isFormatText bool) Logger {
	return &logger{
		component:     component,
		task:          component,
		sinks:         []Sink{},
		data:          openlogging.Tags{},
		logFormatText: isFormatText,
	}
}
689705
func NewFormatedReporter(verbose bool, width int, output io.Writer) Reporter {
	return &FormatedReporter{
		verbose: verbose,
		width:   width,
		output:  output,
	}
}