本文整理匯總了Golang中github.com/blacklightops/libbeat/logp.Info函數的典型用法代碼示例。如果您正苦於以下問題:Golang Info函數的具體用法?Golang Info怎麽用?Golang Info使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Info函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Run
func (l *UdpInput) Run(output chan common.MapStr) error {
logp.Info("[UdpInput] Running UDP Input")
addr := net.UDPAddr{
Port: l.Port,
IP: net.ParseIP("0.0.0.0"),
}
server, err := net.ListenUDP("udp", &addr)
server.SetReadBuffer(1048576)
if err != nil {
logp.Err("couldn't start listening: " + err.Error())
return nil
}
logp.Info("[UdpInput] Listening on port %d", l.Port)
i := 0
for {
i++
buf := make([]byte, 4096)
rlen, addr, err := server.ReadFromUDP(buf)
if err != nil {
logp.Err("couldn't read from UDP: " + err.Error())
}
go l.handlePacket(buf, rlen, i, addr, output)
}
return nil
}
示例2: Run
func (reader *ReaderType) Run(output chan common.MapStr) error {
logp.Info("Attempting to start %d inputs", len(reader.Input))
for _, plugin := range reader.Input {
err := plugin.Run(output)
if err != nil {
logp.Err("Fail to start input plugin %s : %s", plugin.InputType(), err)
return err
} else {
logp.Info("Started input plugin %s", plugin.InputType())
}
}
return nil
}
示例3: Init
func (l *TailInput) Init(config inputs.MothershipConfig) error {
l.Type = "tail"
l.Config = config
l.FileName = config.Filename
l.RollTime = 30 * time.Minute
logp.Info("[TailInput] Initialized with file " + l.FileName)
return nil
}
示例4: Init
func (l *SyslogInput) Init(config inputs.MothershipConfig) error {
l.Config = config
if config.Port == 0 {
return errors.New("No Input Port specified")
}
l.Port = config.Port
if config.Type == "" {
return errors.New("No Event Type specified")
}
l.Type = config.Type
logp.Info("[SyslogInput] Using Port %d", l.Port)
logp.Info("[SyslogInput] Adding Event Type %s", l.Type)
return nil
}
示例5: Init
func (l *ProcfsInput) Init(config inputs.MothershipConfig) error {
l.Config = config
l.Tick_interval = config.Tick_interval
logp.Info("[ProcfsInput] Initialized, using tick interval " + strconv.Itoa(l.Tick_interval))
return nil
}
示例6: writeHeapProfile
func writeHeapProfile(filename string) {
f, err := os.Create(filename)
if err != nil {
logp.Err("Failed creating file %s: %s", filename, err)
return
}
pprof.WriteHeapProfile(f)
f.Close()
logp.Info("Created memory profile file %s.", filename)
}
示例7: doStuff
func (l *PackagesInput) doStuff(output chan common.MapStr) {
now := func() time.Time {
t := time.Now()
return t
}
// construct event and write it to channel
event := common.MapStr{}
//text := "null event"
//event["message"] = &text
event["message"] = "packages event"
event["type"] = l.Type
event.EnsureTimestampField(now)
event.EnsureCountField()
/////////////
cmd := exec.Command("/bin/rpm", "-qa", "--queryformat", "%{NAME}:::%{VERSION}:::%{ARCH}##")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
logp.Info("Error occurred")
return
}
items := strings.Split(out.String(), "##")
rpmList := make([]RPMPackage, 0)
for _, line := range items {
item := strings.Split(line, ":::")
if len(item) < 3 {
continue
}
pkg := RPMPackage{
Name: item[0],
Version: item[1],
Arch: item[2],
}
rpmList = append(rpmList, pkg)
}
event["packages"] = rpmList
output <- event
}
示例8: Init
func (out *KafkaOutput) Init(config outputs.MothershipConfig, topology_expire int) error {
if config.Host == "" {
return errors.New("No Kafka brokers specified")
}
out.BrokerList = strings.Split(config.Host, ",")
if config.Topic == "" {
return errors.New("No Kafka topic specified")
}
out.Topic = config.Topic
out.Timeout = 5 * time.Second
if config.Timeout != 0 {
out.Timeout = time.Duration(config.Timeout) * time.Second
}
out.FlushInterval = 1000 * time.Millisecond
out.ReconnectInterval = time.Duration(1) * time.Second
if config.Reconnect_interval != 0 {
out.ReconnectInterval = time.Duration(config.Reconnect_interval) * time.Second
}
//sarama.Logger = log.New(os.Stdout, "[KafkaOutput]", log.LstdFlags)
logp.Info("[KafkaOutput] Using Kafka brokers %s", config.Host)
logp.Info("[KafkaOutput] Kafka connection timeout %s", out.Timeout)
logp.Info("[KafkaOutput] Kafka reconnect interval %s", out.ReconnectInterval)
logp.Info("[KafkaOutput] Kafka flushing interval %s", out.FlushInterval)
logp.Info("[KafkaOutput] Publishing to topic %s", out.Topic)
out.sendingQueue = make(chan KafkaQueueMsg, 1000)
out.Reconnect()
go out.SendMessagesGoroutine()
return nil
}
示例9: Run
func (l *TcpInput) Run(output chan common.MapStr) error {
logp.Info("[TcpInput] Running TCP Input")
server, err := net.Listen("tcp", ":"+strconv.Itoa(l.Port))
if err != nil {
logp.Err("couldn't start listening: " + err.Error())
return nil
}
logp.Info("[TcpInput] Listening on port %d", l.Port)
// dispatch the master listen thread
go func(server net.Listener) {
for {
// accept incoming connections
conn, err := server.Accept()
if err != nil {
logp.Err("Error accepting: ", err.Error())
} else {
// dispatch individual connection handler threads
go l.handleConn(conn, output)
}
}
}(server)
return nil
}
示例10: doStuff
func (l *StdinInput) doStuff(output chan common.MapStr) {
reader := bufio.NewReader(os.Stdin)
buffer := new(bytes.Buffer)
var source string = fmt.Sprintf("%s:%s", os.Getenv("REMOTE_HOST"), os.Getenv("REMOTE_PORT"))
var ssl_client_dn string = os.Getenv("SSL_CLIENT_DN")
var offset int64 = 0
var line uint64 = 0
var read_timeout = 10 * time.Second
logp.Debug("stdinput", "Handling New Connection from %s", source)
now := func() time.Time {
t := time.Now()
return t
}
for {
text, bytesread, err := l.readline(reader, buffer, read_timeout)
if err != nil {
logp.Info("Unexpected state reading from %v; error: %s\n", os.Getenv("SSL_CLIENT_DN"), err)
return
}
logp.Debug("stdinputlines", "New Line: %s", &text)
line++
event := common.MapStr{}
event["ssl_client_dn"] = &ssl_client_dn
event["source"] = &source
event["offset"] = offset
event["line"] = line
event["message"] = text
event["type"] = l.Type
event.EnsureTimestampField(now)
event.EnsureCountField()
offset += int64(bytesread)
logp.Debug("stdinput", "InputEvent: %v", event)
output <- event // ship the new event downstream
os.Stdout.Write([]byte("OK"))
}
logp.Debug("stdinput", "Closed Connection from %s", source)
}
示例11: LoadGeoIPData
func LoadGeoIPData(config Geoip) *libgeo.GeoIP {
geoip_paths := []string{
"/usr/share/GeoIP/GeoIP.dat",
"/usr/local/var/GeoIP/GeoIP.dat",
}
if config.Paths != nil {
geoip_paths = *config.Paths
}
if len(geoip_paths) == 0 {
// disabled
return nil
}
// look for the first existing path
var geoip_path string
for _, path := range geoip_paths {
fi, err := os.Lstat(path)
if err != nil {
continue
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
// follow symlink
geoip_path, err = filepath.EvalSymlinks(path)
if err != nil {
logp.Warn("Could not load GeoIP data: %s", err.Error())
return nil
}
} else {
geoip_path = path
}
break
}
if len(geoip_path) == 0 {
logp.Warn("Couldn't load GeoIP database")
return nil
}
geoLite, err := libgeo.Load(geoip_path)
if err != nil {
logp.Warn("Could not load GeoIP data: %s", err.Error())
}
logp.Info("Loaded GeoIP data from: %s", geoip_path)
return geoLite
}
示例12: handleConn
func (l *TcpInput) handleConn(client net.Conn, output chan common.MapStr) {
reader := bufio.NewReader(client)
buffer := new(bytes.Buffer)
var source string = client.RemoteAddr().String()
var offset int64 = 0
var line uint64 = 0
var read_timeout = 10 * time.Second
logp.Debug("tcpinput", "Handling New Connection from %s", source)
now := func() time.Time {
t := time.Now()
return t
}
for {
text, bytesread, err := l.readline(reader, buffer, read_timeout)
if err != nil {
logp.Info("Unexpected state reading from %v; error: %s\n", client.RemoteAddr().String, err)
return
}
logp.Debug("tcpinputlines", "New Line: %s", &text)
line++
event := common.MapStr{}
event["source"] = &source
event["offset"] = offset
event["line"] = line
event["message"] = text
event["type"] = l.Type
event.EnsureTimestampField(now)
event.EnsureCountField()
offset += int64(bytesread)
logp.Debug("tcpinput", "InputEvent: %v", event)
output <- event // ship the new event downstream
client.Write([]byte("OK"))
}
logp.Debug("tcpinput", "Closed Connection from %s", source)
}
示例13: newInputInstance
func newInputInstance(name string) inputs.InputInterface {
logp.Info("creating new instance of type %s", name)
switch name {
case "tcp":
return new(tcp.TcpInput)
case "udp":
return new(udp.UdpInput)
case "tail":
return new(tail.TailInput)
case "syslog":
return new(syslog.SyslogInput)
case "procfs":
return new(procfs.ProcfsInput)
case "packages":
return new(packages.PackagesInput)
case "null":
return new(null.NullInput)
}
return nil
}
示例14: Init
func (reader *ReaderType) Init(inputMap map[string]inputs.MothershipConfig) error {
logp.Info("reader input config", inputMap)
var globalConf inputs.MothershipConfig
for inputId, config := range inputMap {
// default instance 0
inputName, instance := inputId, "0"
if strings.Contains(inputId, "_") {
// otherwise grok tcp_2 as inputName = tcp, instance = 2
sv := strings.Split(inputId, "_")
inputName, instance = sv[0], sv[1]
}
logp.Info(fmt.Sprintf("input type: %s instance: %s\n", inputName, instance))
logp.Debug("reader", "instance config: %s", config)
// handling for "global" config section
if inputName == "global" {
logp.Info("global input configuration read")
globalConf = config
}
plugin := newInputInstance(inputName)
if plugin != nil && config.Enabled {
config.Normalize(globalConf)
err := plugin.Init(config)
if err != nil {
logp.Err("Fail to initialize %s plugin as input: %s", inputName, err)
return err
} else {
logp.Info("Initialized %s plugin as input", inputName)
}
reader.Input = append(reader.Input, plugin)
}
}
if len(reader.Input) == 0 {
logp.Info("No inputs are defined. Please define one under the input section.")
return errors.New("No input are defined. Please define one under the input section.")
} else {
logp.Info("%d inputs defined", len(reader.Input))
}
return nil
}
示例15: DropPrivileges
func DropPrivileges(config RunOptions) error {
var err error
if config.Uid == nil {
// not found, no dropping privileges but no err
return nil
}
if config.Gid == nil {
return errors.New("GID must be specified for dropping privileges")
}
logp.Info("Switching to user: %d.%d", config.Uid, config.Gid)
if err = syscall.Setgid(*config.Gid); err != nil {
return fmt.Errorf("setgid: %s", err.Error())
}
if err = syscall.Setuid(*config.Uid); err != nil {
return fmt.Errorf("setuid: %s", err.Error())
}
return nil
}