本文整理匯總了Golang中github.com/elastic/libbeat/logp.Debug函數的典型用法代碼示例。如果您正苦於以下問題:Golang Debug函數的具體用法?Golang Debug怎麽用?Golang Debug使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Debug函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Cleanup
func (eb *Winlogbeat) Cleanup(b *beat.Beat) error {
logp.Debug("winlogbeat", "Dumping runtime metrics...")
expvar.Do(func(kv expvar.KeyValue) {
logp.Debug("winlogbeat", "%s=%s", kv.Key, kv.Value.String())
})
return nil
}
示例2: ConfigSetup
func (beat *Beat) ConfigSetup(beater Beater, inputConfig interface{}) {
config := &ConfigSettings{
//Input: inputConfig,
}
err := cfgfile.Read(config)
beat.Config = *config
if err != nil {
logp.Debug("Log read error", "Error %v\n", err)
}
logp.Init(beat.Name, &beat.Config.Logging)
logp.Debug("main", "Initializing output plugins")
if err := publisher.Publisher.Init(beat.Config.Output, beat.Config.Shipper); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
beat.events = publisher.Publisher.Queue
logp.Debug(beat.Name, "Init %s", beat.Name)
if err := beater.Init(beat); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
}
示例3: Config
func (d *Dockerbeat) Config(b *beat.Beat) error {
err := cfgfile.Read(&d.TbConfig, "")
if err != nil {
logp.Err("Error reading configuration file: %v", err)
return err
}
//init the period
if d.TbConfig.Input.Period != nil {
d.period = time.Duration(*d.TbConfig.Input.Period) * time.Second
} else {
d.period = 1 * time.Second
}
//init the socket
if d.TbConfig.Input.Socket != nil {
d.socket = *d.TbConfig.Input.Socket
} else {
d.socket = "unix:///var/run/docker.sock" // default docker socket location
}
logp.Debug("dockerbeat", "Init dockerbeat")
logp.Debug("dockerbeat", "Follow docker socket %q\n", d.socket)
logp.Debug("dockerbeat", "Period %v\n", d.period)
return nil
}
示例4: Config
// Config Uwsgibeat according to uwsgibeat.yml.
func (ub *Uwsgibeat) Config(b *beat.Beat) error {
err := cfgfile.Read(&ub.UbConfig, "")
if err != nil {
logp.Err("Error reading configuration file: %v", err)
return err
}
var u string
if ub.UbConfig.Input.URL != "" {
u = ub.UbConfig.Input.URL
} else {
u = "127.0.0.1:1717"
}
ub.url, err = url.Parse(u)
if err != nil {
logp.Err("Invalid uWSGI stats server address: %v", err)
return err
}
if ub.UbConfig.Input.Period != nil {
ub.period = time.Duration(*ub.UbConfig.Input.Period) * time.Second
} else {
ub.period = 1 * time.Second
}
logp.Debug(selector, "Init uwsgibeat")
logp.Debug(selector, "Watch %v", ub.url)
logp.Debug(selector, "Period %v", ub.period)
return nil
}
示例5: FindSocketsOfPid
func FindSocketsOfPid(prefix string, pid int) (inodes []int64, err error) {
dirname := filepath.Join(prefix, "/proc", strconv.Itoa(pid), "fd")
procfs, err := os.Open(dirname)
if err != nil {
return []int64{}, fmt.Errorf("Open: %s", err)
}
names, err := procfs.Readdirnames(0)
if err != nil {
return []int64{}, fmt.Errorf("Readdirnames: %s", err)
}
for _, name := range names {
link, err := os.Readlink(filepath.Join(dirname, name))
if err != nil {
logp.Debug("procs", "Readlink %s: %s", name, err)
continue
}
if strings.HasPrefix(link, "socket:[") {
inode, err := strconv.ParseInt(link[8:len(link)-1], 10, 64)
if err != nil {
logp.Debug("procs", "ParseInt: %s:", err)
continue
}
inodes = append(inodes, int64(inode))
}
}
return inodes, nil
}
示例6: handleReadlineError
// handleReadlineError handles error which are raised during reading file.
//
// If error is EOF, it will check for:
// * File truncated
// * Older then ignore_older
// * General file error
//
// If none of the above cases match, no error will be returned and file is kept open
//
// In case of a general error, the error itself is returned
func (h *Harvester) handleReadlineError(lastTimeRead time.Time, err error) error {
if err == io.EOF {
// Refetch fileinfo to check if the file was truncated or disappeared
info, statErr := h.file.Stat()
// This could happen if the file was removed / rotate after reading and before calling the stat function
if statErr != nil {
logp.Err("Unexpected error reading from %s; error: %s", h.Path, statErr)
return statErr
}
// Check if file was truncated
if info.Size() < h.Offset {
logp.Debug("harvester", "File was truncated as offset > size. Begin reading file from offset 0: %s", h.Path)
h.Offset = 0
h.file.Seek(h.Offset, os.SEEK_SET)
} else if age := time.Since(lastTimeRead); age > h.ProspectorConfig.IgnoreOlderDuration {
// If the file hasn't change for longer the ignore_older, harvester stops and file handle will be closed.
logp.Debug("harvester", "Stopping harvesting of file as older then ignore_old: ", h.Path, "Last change was: ", age)
return err
}
// Do nothing in case it is just EOF, keep reading the file
return nil
} else {
logp.Err("Unexpected state reading from %s; error: %s", h.Path, err)
return err
}
}
示例7: Scan
func (restart *ProspectorResume) Scan(files []cfg.FileConfig, persist map[string]*FileState, eventChan chan *FileEvent) {
pendingProspectorCnt := 0
// Prospect the globs/paths given on the command line and launch harvesters
for _, fileconfig := range files {
prospector := &Prospector{FileConfig: fileconfig}
go prospector.Prospect(restart, eventChan)
pendingProspectorCnt++
}
// Now determine which states we need to persist by pulling the events from the prospectors
// When we hit a nil source a prospector had finished so we decrease the expected events
logp.Debug("prospector", "Waiting for %d prospectors to initialise", pendingProspectorCnt)
for event := range restart.Persist {
if event.Source == nil {
pendingProspectorCnt--
if pendingProspectorCnt == 0 {
break
}
continue
}
persist[*event.Source] = event
logp.Debug("prospector", "Registrar will re-save state for %s", *event.Source)
}
logp.Info("All prospectors initialised with %d states to persist", len(persist))
}
示例8: LoadConfig
// LoadConfig inits the config file and reads the default config information
// into Beat.Config. It exists the processes in case of errors.
func (b *Beat) LoadConfig() {
err := cfgfile.Read(&b.Config, "")
if err != nil {
// logging not yet initialized, so using fmt.Printf
fmt.Printf("Loading config file error: %v\n", err)
os.Exit(1)
}
err = logp.Init(b.Name, &b.Config.Logging)
if err != nil {
fmt.Printf("Error initializing logging: %v\n", err)
os.Exit(1)
}
// Disable stderr logging if requested by cmdline flag
logp.SetStderr()
logp.Debug("beat", "Initializing output plugins")
if err := publisher.Publisher.Init(b.Name, b.Config.Output, b.Config.Shipper); err != nil {
fmt.Printf("Error Initialising publisher: %v\n", err)
logp.Critical(err.Error())
os.Exit(1)
}
b.Events = publisher.Publisher.Client()
logp.Debug("beat", "Init %s", b.Name)
}
示例9: calculateResume
func (p *Prospector) calculateResume(file string, fileinfo os.FileInfo, resume *ProspectorResume) (int64, bool) {
last_state, is_found := resume.Files[file]
if is_found && IsSameFile(file, fileinfo, last_state) {
// We're resuming - throw the last state back downstream so we resave it
// And return the offset - also force harvest in case the file is old and we're about to skip it
resume.Persist <- last_state
return last_state.Offset, true
}
if previous := p.isFileRenamedResumelist(file, fileinfo, resume.Files); previous != "" {
// File has rotated between shutdown and startup
// We return last state downstream, with a modified event source with the new file name
// And return the offset - also force harvest in case the file is old and we're about to skip it
logp.Debug("prospector", "Detected rename of a previously harvested file: %s -> %s", previous, file)
last_state := resume.Files[previous]
last_state.Source = &file
resume.Persist <- last_state
return last_state.Offset, true
}
if is_found {
logp.Debug("prospector", "Not resuming rotated file: %s", file)
}
// New file so just start from an automatic position
return 0, false
}
示例10: Config
func (tb *Topbeat) Config(b *beat.Beat) error {
err := cfgfile.Read(&tb.TbConfig, "")
if err != nil {
logp.Err("Error reading configuration file: %v", err)
return err
}
if tb.TbConfig.Input.Period != nil {
tb.period = time.Duration(*tb.TbConfig.Input.Period) * time.Second
} else {
tb.period = 1 * time.Second
}
if tb.TbConfig.Input.Procs != nil {
tb.procs = *tb.TbConfig.Input.Procs
} else {
tb.procs = []string{".*"} //all processes
}
logp.Debug("topbeat", "Init toppbeat")
logp.Debug("topbeat", "Follow processes %q\n", tb.procs)
logp.Debug("topbeat", "Period %v\n", tb.period)
return nil
}
示例11: Publish
func Publish(beat *beat.Beat, fb *Filebeat) {
// Receives events from spool during flush
for events := range fb.publisherChan {
logp.Debug("filebeat", "Send events to output")
pubEvents := make([]common.MapStr, 0, len(events))
for _, event := range events {
bEvent := common.MapStr{
"timestamp": common.Time(time.Now()),
"source": event.Source,
"offset": event.Offset,
"line": event.Line,
"message": event.Text,
"fields": event.Fields,
"fileinfo": event.Fileinfo,
"type": "log",
}
pubEvents = append(pubEvents, bEvent)
}
beat.Events.PublishEvents(pubEvents, publisher.Sync)
logp.Debug("filebeat", "Events sent: %d", len(events))
// Tell the registrar that we've successfully sent these events
fb.registrar.Channel <- events
}
}
示例12: ParseUdp
func (dns *Dns) ParseUdp(pkt *protos.Packet) {
defer logp.Recover("Dns ParseUdp")
logp.Debug("dns", "Parsing packet addressed with %s of length %d.",
pkt.Tuple.String(), len(pkt.Payload))
dnsPkt, err := decodeDnsPacket(pkt.Payload)
if err != nil {
// This means that malformed requests or responses are being sent or
// that someone is attempting to the DNS port for non-DNS traffic. Both
// are issues that a monitoring system should report.
logp.Debug("dns", NonDnsPacketMsg+" addresses %s, length %d",
pkt.Tuple.String(), len(pkt.Payload))
return
}
dnsTuple := DnsTupleFromIpPort(&pkt.Tuple, TransportUdp, dnsPkt.ID)
dnsMsg := &DnsMessage{
Ts: pkt.Ts,
Tuple: pkt.Tuple,
CmdlineTuple: procs.ProcWatcher.FindProcessesTuple(&pkt.Tuple),
Data: dnsPkt,
Length: len(pkt.Payload),
}
if dnsMsg.Data.QR == Query {
dns.receivedDnsRequest(&dnsTuple, dnsMsg)
} else /* Response */ {
dns.receivedDnsResponse(&dnsTuple, dnsMsg)
}
}
示例13: LoadConfig
// LoadConfig inits the config file and reads the default config information
// into Beat.Config. It exists the processes in case of errors.
func (b *Beat) LoadConfig() {
err := cfgfile.Read(&b.Config, "")
if err != nil {
// logging not yet initialized, so using fmt.Printf
fmt.Printf("%v\n", err)
os.Exit(1)
}
err = logp.Init(b.Name, &b.Config.Logging)
if err != nil {
fmt.Printf("Error initializing logging: %v\n", err)
os.Exit(1)
}
logp.Debug("beat", "Initializing output plugins")
if err := publisher.Publisher.Init(b.Name, b.Version, b.Config.Output, b.Config.Shipper); err != nil {
logp.Critical(err.Error())
os.Exit(1)
}
b.Events = publisher.Publisher.Client()
logp.Debug("beat", "Init %s", b.Name)
}
示例14: handleReadlineError
// Handles error during reading file. If EOF and nothing special, exit without errors
func (h *Harvester) handleReadlineError(lastTimeRead time.Time, err error) error {
if err == io.EOF {
// timed out waiting for data, got eof.
// Check to see if the file was truncated
info, _ := h.file.Stat()
if h.ProspectorConfig.IgnoreOlder != "" {
logp.Debug("harvester", "Ignore Unmodified After: %s", h.ProspectorConfig.IgnoreOlder)
}
if info.Size() < h.Offset {
logp.Debug("harvester", "File truncated, seeking to beginning: %s", h.Path)
h.file.Seek(0, os.SEEK_SET)
h.Offset = 0
} else if age := time.Since(lastTimeRead); age > h.ProspectorConfig.IgnoreOlderDuration {
// if lastTimeRead was more than ignore older and ignore older is set, this file is probably dead. Stop watching it.
logp.Debug("harvester", "Stopping harvest of ", h.Path, "last change was: ", age)
return err
}
} else {
logp.Err("Unexpected state reading from %s; error: %s", h.Path, err)
return err
}
return nil
}
示例15: initFileOffset
func (h *Harvester) initFileOffset(file *os.File) error {
offset, err := file.Seek(0, os.SEEK_CUR)
if h.Offset > 0 {
// continue from last known offset
logp.Debug("harvester",
"harvest: %q position:%d (offset snapshot:%d)", h.Path, h.Offset, offset)
_, err = file.Seek(h.Offset, os.SEEK_SET)
} else if h.Config.TailFiles {
// tail file if file is new and tail_files config is set
logp.Debug("harvester",
"harvest: (tailing) %q (offset snapshot:%d)", h.Path, offset)
h.Offset, err = file.Seek(0, os.SEEK_END)
} else {
// get offset from file in case of encoding factory was
// required to read some data.
logp.Debug("harvester", "harvest: %q (offset snapshot:%d)", h.Path, offset)
h.Offset = offset
}
return err
}