Add script to add documentation to readme
This commit is contained in:
parent
4cb0b027cd
commit
32d681703c
7
main.go
7
main.go
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -61,7 +60,7 @@ type ContainerStartJob struct {
|
||||
// Run is executed based on the ContainerStartJob Schedule and starts the
|
||||
// container
|
||||
func (job ContainerStartJob) Run() {
|
||||
log.Println("Starting:", job.name)
|
||||
slog.Log("Starting: %s", job.name)
|
||||
|
||||
// Check if container is already running
|
||||
containerJSON, err := job.client.ContainerInspect(
|
||||
@ -133,7 +132,7 @@ type ContainerExecJob struct {
|
||||
// Run is executed based on the ContainerStartJob Schedule and starts the
|
||||
// container
|
||||
func (job ContainerExecJob) Run() {
|
||||
log.Println("Execing:", job.name)
|
||||
slog.Log("Execing: %s", job.name)
|
||||
containerJSON, err := job.client.ContainerInspect(
|
||||
job.context,
|
||||
job.containerID,
|
||||
@ -270,7 +269,7 @@ func ScheduleJobs(c *cron.Cron, jobs []ContainerCronJob) {
|
||||
// Job doesn't exist yet, schedule it
|
||||
_, err := c.AddJob(job.Schedule(), job)
|
||||
if err == nil {
|
||||
log.Printf(
|
||||
slog.Log(
|
||||
"Scheduled %s (%s) with schedule '%s'\n",
|
||||
job.Name(),
|
||||
job.UniqueName(),
|
||||
|
@ -9,3 +9,40 @@ _Slog is not one of them._
|
||||
Slog lets you hide or show debug logs as well as provides a simpler way to log messages with Warning and Error prefixes for consistency.
|
||||
|
||||
Also provided are a few simple methods for handling returned `error` variables, logging them out and optionally panicing or fatally exiting.
|
||||
|
||||
## Documentation
|
||||
package slog // import "github.com/iamthefij/dockron/slog"
|
||||
|
||||
Package slog is a super simple logger that allows a few convenience methods
|
||||
for handling debug vs warning/error logs. It also adds a few conveniences
|
||||
for handling errors.
|
||||
|
||||
VARIABLES
|
||||
|
||||
var (
|
||||
// DebugLevel indicates if we should log at the debug level
|
||||
DebugLevel = true
|
||||
)
|
||||
|
||||
FUNCTIONS
|
||||
|
||||
func FatalErr(err error, format string, v ...interface{})
|
||||
FatalErr if error provided, will log out details of an error and exi
|
||||
|
||||
func Log(format string, v ...interface{})
|
||||
Log formats logs directly to the main logger
|
||||
|
||||
func LogDebug(format string, v ...interface{})
|
||||
LogDebug will log with a DEBUG prefix if DebugLevel is se
|
||||
|
||||
func LogError(format string, v ...interface{})
|
||||
LogError will log with a ERROR prefix
|
||||
|
||||
func LogWarning(format string, v ...interface{})
|
||||
LogWarning will log with a WARNING prefix
|
||||
|
||||
func PanicErr(err error, format string, v ...interface{})
|
||||
PanicErr if error provided, will log out details of an error and exi
|
||||
|
||||
func WarnErr(err error, format string, v ...interface{})
|
||||
WarnErr if error provided, will provide a warning if an error is provided
|
||||
|
8
slog/add-docs-to-readme.sh
Executable file
8
slog/add-docs-to-readme.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#! /bin/bash
|
||||
set -e
|
||||
|
||||
slogdir=$(dirname "$0")
|
||||
readme="$slogdir/Readme.md"
|
||||
|
||||
awk '/## Documentation/ {print ; exit} {print}' "$readme" > "$readme.tmp" && go doc -all slog | sed "s/^/ /;s/[ \t]*$//" >> "$readme.tmp"
|
||||
mv "$readme.tmp" "$readme"
|
15
slog/slog.go
15
slog/slog.go
@ -1,3 +1,6 @@
|
||||
// Package slog is a super simple logger that allows a few convenience methods
|
||||
// for handling debug vs warning/error logs. It also adds a few conveniences for
|
||||
// handling errors.
|
||||
package slog
|
||||
|
||||
import (
|
||||
@ -9,11 +12,17 @@ var (
|
||||
// DebugLevel indicates if we should log at the debug level
|
||||
DebugLevel = true
|
||||
|
||||
// Loggers for various levels
|
||||
loggerDebug = log.New(os.Stderr, "DEBUG", log.LstdFlags)
|
||||
loggerWarning = log.New(os.Stderr, "WARNING", log.LstdFlags)
|
||||
loggerError = log.New(os.Stderr, "ERROR", log.LstdFlags)
|
||||
)
|
||||
|
||||
// Log formats logs directly to the main logger
|
||||
func Log(format string, v ...interface{}) {
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
|
||||
// LogDebug will log with a DEBUG prefix if DebugLevel is set
|
||||
func LogDebug(format string, v ...interface{}) {
|
||||
if !DebugLevel {
|
||||
@ -32,7 +41,7 @@ func LogError(format string, v ...interface{}) {
|
||||
loggerError.Printf(format, v...)
|
||||
}
|
||||
|
||||
// WarnErr will provide a warning if an error is provided
|
||||
// WarnErr if error provided, will provide a warning if an error is provided
|
||||
func WarnErr(err error, format string, v ...interface{}) {
|
||||
if err != nil {
|
||||
loggerWarning.Printf(format, v...)
|
||||
@ -40,7 +49,7 @@ func WarnErr(err error, format string, v ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// FatalErr will log out details of an error and exit
|
||||
// FatalErr if error provided, will log out details of an error and exit
|
||||
func FatalErr(err error, format string, v ...interface{}) {
|
||||
if err != nil {
|
||||
loggerError.Printf(format, v...)
|
||||
@ -48,7 +57,7 @@ func FatalErr(err error, format string, v ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// PanicErr will log out details of an error and exit
|
||||
// PanicErr if error provided, will log out details of an error and exit
|
||||
func PanicErr(err error, format string, v ...interface{}) {
|
||||
if err != nil {
|
||||
loggerError.Printf(format, v...)
|
||||
|
Loading…
Reference in New Issue
Block a user