Exemplo n.º 1
0
func (v *aspContext) InstallSignals() {
	// install signals.
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

	go func() {
		for s := range sigs {
			ol.T(v.ctx, "go signal", s)

			if v.callback != nil {
				v.callback()
			}

			os.Exit(0)
		}
	}()
	ol.T(v.ctx, "signal watched by asprocess")
}
Exemplo n.º 2
0
func ExampleLogger_ToConsole() {
	// Simply log to console.
	ol.Info.Println(nil, "The log text.")
	ol.Trace.Println(nil, "The log text.")
	ol.Warn.Println(nil, "The log text.")
	ol.Error.Println(nil, "The log text.")

	// Use short aliases.
	ol.I(nil, "The log text.")
	ol.T(nil, "The log text.")
	ol.W(nil, "The log text.")
	ol.E(nil, "The log text.")
}
Exemplo n.º 3
0
func ExampleLogger_ToFile() {
	// Open logger file and change the tank for logger.
	var err error
	var f *os.File
	if f, err = os.Open("sys.log"); err != nil {
		return
	}
	ol.Switch(f)

	// Use logger, which will write to file.
	ol.T(nil, "The log text.")

	// Close logger file when your application quit.
	defer ol.Close()
}
Exemplo n.º 4
0
func (v *aspContextNoExit) WatchParent() {
	ppid := os.Getppid()

	go func() {
		for {
			if pid := os.Getppid(); pid == 1 || pid != ppid {
				ol.E(v.ctx, "quit for parent problem, ppid is", pid)
				select {
				case v.quit <- true:
				default:
				}
				break
			}
			//ol.T(v.ctx, "parent pid", ppid, "ok")

			time.Sleep(v.interval)
		}
	}()
	ol.T(v.ctx, "parent process watching, ppid is", ppid)
}
Exemplo n.º 5
0
func (v *aspContext) WatchParent() {
	ppid := os.Getppid()

	go func() {
		for {
			if pid := os.Getppid(); pid == 1 || pid != ppid {
				ol.E(v.ctx, "quit for parent problem, ppid is", pid)

				if v.callback != nil {
					v.callback()
				}

				os.Exit(0)
			}
			//ol.T(v.ctx, "parent pid", ppid, "ok")

			time.Sleep(v.interval)
		}
	}()
	ol.T(v.ctx, "parent process watching, ppid is", ppid)
}