proc

package module
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2022 License: Unlicense Imports: 10 Imported by: 12

README

proc

Process control, logging and child processes

Description

Golang is a great language for concurrency, but sometimes you want parallelism, and it's often simpler to design apps as little units that plug together via RPC APIs. Services don't always have easy start/stop/reconfig/restart controls, and sometimes they use their own custom configuration scheme that is complicated to integrate with yours.

In addition, you may want to design your applications as neat little pieces, but how to attach them together and orchestrate them starting up and coming down cleanly, and not have to deal with several different ttys to get the logs.

Proc creates a simple framework for creating observable, controllable execution units out of your code, and more easily integrating the code of others.

This project is the merge of several libraries for logging, spawning and controlling child processes, and creating an RPC to child processes that controls the run of the child process. Due to the confusing duplication of signals as a means of control and the lack of uniformity in signals (ie windows) the goal of proc is to create one way to do, following the principles of design used for Go itself.

Badges

<insert badges here

Installation

For developers:

To make nice tagged versions with the version number in the commit as well as matching to the tag, there is a tool called bumper that bumps the version to the next patch version (vX.X.PATCH), embeds this new version number into version.go with the matching git commit hash of the parent commit. This will make importing this library at an exact commit much more human.

In addition, it makes it easy to make a nice multi line commit message as many repositories request in their CONTRIBUTION file by replacing -- with two carriage returns.

To install:

go install ./bumper/.

To use:

bumper make a commit comment here -- text after double \
    hyphen will be separated by a carriage return -- \
    anywhere in the text

To automatically bump the minor version use minor as the first word of the comment. For the major version major.

Usage

reasonably include in the README.

Support

Roadmap

  • Implement basic logger v0.0.x
  • Create concurrent safe configuration CLI/env/config system v0.1.x
    • Created types with mutex/atomic locks to prevent concurrent access
    • Created key value map type containing collections of concurrent safe values with concurrent safe access to members
    • Create JSON marshal/unmarshal for configuration collections
    • Created tests for generating and concurrently accessing/mutating data
    • Save and load configuration from file (using json, with all values stored in file, no unnecessary comments)
    • Generate CLI help texts from configs specifications
    • Read values from environment variables overlay on config file values
    • Created command line parsing system overlay values above previous
  • Child process control system v0.2.x
    • Launch, pause, continue and stop child process. Use only one method: the IPC API, no complication with signals.
    • Read and pass through logging from child process
    • Correctly handle process signals from OS/tty to trigger orderly shutdown of child processes and leave none orphaned
    • Create a Rust implementation of the child process control interface so Rust services/libraries can be seamlessly integrated without FFI annoyances.
  • Build system that wraps around go to automatically update modified generators transparently.

Contributing

Authors and acknowledgment

David Vennik david@cybriq.systems

License

Unlicenced: see here

Project status

In the process of revision and merging together several related libraries that need to be unified.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// App is the name of the application. Change this at the beginning of
	// an application main.
	App = "  main"
	// AllSubsystems stores all of the package subsystem names found in the current
	// application.
	AllSubsystems []string
)
View Source
var (
	// URL is the git URL for the repository
	URL = "github.com/cybriq/proc"
	// GitRef is the gitref, as in refs/heads/branchname
	GitRef = "refs/heads/master"
	// ParentGitCommit is the commit hash of the parent HEAD
	ParentGitCommit = "54a127c991c1c4c98d3c6e5a19a14a6b15758d0c"
	// BuildTime stores the time when the current binary was built
	BuildTime = "2022-08-11T10:07:22+02:00"
	// SemVer lists the (latest) git tag on the build
	SemVer = "v0.1.10"
	// PathBase is the path base returned from runtime caller
	PathBase = "/home/loki/src/github.com/cybriq/proc/"
	// Major is the major number from the tag
	Major = 0
	// Minor is the minor number from the tag
	Minor = 1
	// Patch is the patch version number from the tag
	Patch = 10
)
View Source
var LevelSpecs = map[LogLevel]LevelSpec{
	Off:   gLS(Off, 0, 0, 0),
	Fatal: gLS(Fatal, 255, 0, 0),
	Error: gLS(Error, 255, 128, 0),
	Check: gLS(Check, 255, 255, 0),
	Warn:  gLS(Warn, 255, 255, 0),
	Info:  gLS(Info, 0, 255, 0),
	Debug: gLS(Debug, 0, 128, 255),
	Trace: gLS(Trace, 128, 0, 255),
}

LevelSpecs specifies the id, string name and color-printing function

View Source
var LvlStr = map[LogLevel]string{
	Off:   "off  ",
	Fatal: "fatal",
	Error: "error",
	Warn:  "warn ",
	Info:  "info ",
	Check: "check",
	Debug: "debug",
	Trace: "trace",
}

LvlStr is a map that provides the uniform width strings that are printed to identify the LogLevel of a log entry.

Functions

func Add added in v0.0.30

func Add(pathBase string) (subsystem string)

Add adds a subsystem to the list of known subsystems and returns the string so it is nice and neat in the package logg.go file

func GetLoc added in v0.0.30

func GetLoc(skip int, subsystem string) (output string)

GetLoc calls runtime.Caller and formats as expected by source code editors for terminal hyperlinks

Regular expressions and the substitution texts to make these clickable in Tilix and other RE hyperlink configurable terminal emulators:

This matches the shortened paths generated in this command and printed at the very beginning of the line as this logger prints:

^((([\/a-zA-Z@0-9-_.]+/)+([a-zA-Z@0-9-_.]+)):([0-9]+))
/usr/local/bin/goland --line $5 $GOPATH/src/github.com/p9c/matrjoska/$2

I have used a shell variable there but tilix doesn't expand them, so put your GOPATH in manually, and obviously change the repo subpath.

func SetLogLevel added in v0.0.30

func SetLogLevel(l LogLevel)

func SetTimeStampFormat added in v0.0.30

func SetTimeStampFormat(format string)

SetTimeStampFormat sets a custom timeStampFormat for the logger

func Version added in v0.0.30

func Version() string

Version returns a pretty printed version information string

Types

type Chk

type Chk func(e error) bool

Chk is a shortcut for printing if there is an error, or returning true

type LevelPrinter

type LevelPrinter struct {
	Ln Println
	// F prints like fmt.Println surrounded by log details
	F Printf
	// S uses spew.dump to show the content of a variable
	S Prints
	// C accepts a function so that the extra computation can be avoided if
	// it is not being viewed
	C Printc
	// Chk is a shortcut for printing if there is an error, or returning
	// true
	Chk Chk
}

LevelPrinter defines a set of terminal printing primitives that output with extra data, time, level, and code location

type LevelSpec

type LevelSpec struct {
	Name      string
	Colorizer func(format string, a ...interface{}) string
}

LevelSpec is a key pair of log level and the text colorizer used for it.

type LogLevel

type LogLevel int32

LogLevel is a code representing a scale of importance and context for log entries.

const (
	Off LogLevel = iota
	Fatal
	Error
	Check
	Warn
	Info
	Debug
	Trace
)

The LogLevel settings used in proc

type Logger

type Logger struct {
	F, E, W, I, D, T LevelPrinter
}

Logger is a set of log printers for the various LogLevel items.

func GetLogger added in v0.0.30

func GetLogger(pathBase string) (l *Logger)

GetLogger returns a set of LevelPrinter with their subsystem preloaded

type Printc

type Printc func(closure func() string)

Printc accepts a function so that the extra computation can be avoided if it is not being viewed

type Printf

type Printf func(format string, a ...interface{})

Printf prints like fmt.Println surrounded by log details

type Println

type Println func(a ...interface{})

Println prints lists of interfaces with spaces in between

type Prints

type Prints func(a ...interface{})

Prints prints a spew.Sdump for an interface slice

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL