Skip to content

Commit

Permalink
Merge pull request #352 from fujiwara/fix/trace-log
Browse files Browse the repository at this point in the history
Fix/trace log
  • Loading branch information
fujiwara authored Feb 5, 2024
2 parents 2c57e8c + 7e39f23 commit 212fc14
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 160 deletions.
3 changes: 2 additions & 1 deletion cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ func CLI(ctx context.Context, parse CLIParseFunc) (int, error) {

color.NoColor = opts.Color
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"debug", "info", "warn", "error"},
Levels: []logutils.LogLevel{"trace", "debug", "info", "warn", "error"},
ModifierFuncs: []logutils.ModifierFunc{
logutils.Color(color.FgHiWhite), // trace
logutils.Color(color.FgHiBlack), // debug
nil, // info
logutils.Color(color.FgYellow), // warn
Expand Down
161 changes: 2 additions & 159 deletions cmd/lambroll/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
var Version = "current"

func main() {
os.Exit(_mainv2())
os.Exit(_main())
}

func _mainv2() int {
func _main() int {
lambroll.Version = Version
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, unix.SIGTERM)
defer stop()
Expand All @@ -33,160 +33,3 @@ func _mainv2() int {
}
return exitCode
}
/*
func _main() int {
kingpin.Command("version", "show version")
logLevel := kingpin.Flag("log-level", "log level (trace, debug, info, warn, error)").Default("info").Enum("trace", "debug", "info", "warn", "error")
function := kingpin.Flag("function", "Function file path").Default(lambroll.FindFunctionFilename()).String()
colorDefault := "false"
if isatty.IsTerminal(os.Stdout.Fd()) {
colorDefault = "true"
}
colorOpt := kingpin.Flag("color", "enable colored output").Default(colorDefault).Bool()
opt := lambroll.Option{
Profile: kingpin.Flag("profile", "AWS credential profile name").Default(os.Getenv("AWS_PROFILE")).String(),
Region: kingpin.Flag("region", "AWS region").Default(os.Getenv("AWS_REGION")).String(),
TFState: kingpin.Flag("tfstate", "URL to terraform.tfstate").Default("").String(),
PrefixedTFState: kingpin.Flag("prefixed-tfstate", "key value pair of the prefix for template function name and URL to terraform.tfstate").PlaceHolder("PREFIX=URL").StringMap(),
Endpoint: kingpin.Flag("endpoint", "AWS API Lambda Endpoint").Default("").String(),
Envfile: kingpin.Flag("envfile", "environment files").Strings(),
ExtStr: kingpin.Flag("ext-str", "external string values for Jsonnet").StringMap(),
ExtCode: kingpin.Flag("ext-code", "external code values for Jsonnet").StringMap(),
}
init := kingpin.Command("init", "init function.json")
initOption := lambroll.InitOption{
FunctionName: init.Flag("function-name", "Function name for initialize").Required().String(),
DownloadZip: init.Flag("download", "Download function.zip").Default("false").Bool(),
}
kingpin.Command("list", "list functions")
listOption := lambroll.ListOption{}
deploy := kingpin.Command("deploy", "deploy or create function")
deployOption := lambroll.DeployOption{
FunctionFilePath: function,
Src: deploy.Flag("src", "function zip archive or src dir").Default(".").String(),
ExcludeFile: deploy.Flag("exclude-file", "exclude file").Default(lambroll.IgnoreFilename).String(),
DryRun: deploy.Flag("dry-run", "dry run").Bool(),
Publish: deploy.Flag("publish", "publish function").Default("true").Bool(),
AliasName: deploy.Flag("alias", "alias name for publish").Default(lambroll.CurrentAliasName).String(),
AliasToLatest: deploy.Flag("alias-to-latest", "set alias to unpublished $LATEST version").Default("false").Bool(),
SkipArchive: deploy.Flag("skip-archive", "skip to create zip archive. requires Code.S3Bucket and Code.S3Key in function definition").Default("false").Bool(),
KeepVersions: deploy.Flag("keep-versions", "Number of latest versions to keep. Older versions will be deleted. (Optional value: default 0).").Default("0").Int(),
Ignore: deploy.Flag("ignore", `ignore function elements. jq queries joined with ",". for example, ".Foo, .Bar"`).String(),
}
rollback := kingpin.Command("rollback", "rollback function")
rollbackOption := lambroll.RollbackOption{
FunctionFilePath: function,
DeleteVersion: rollback.Flag("delete-version", "Delete rolled back version").Bool(),
DryRun: rollback.Flag("dry-run", "dry run").Bool(),
}
delete := kingpin.Command("delete", "delete function")
deleteOption := lambroll.DeleteOption{
FunctionFilePath: function,
DryRun: delete.Flag("dry-run", "dry run").Bool(),
}
invoke := kingpin.Command("invoke", "invoke function")
invokeOption := lambroll.InvokeOption{
FunctionFilePath: function,
Async: invoke.Flag("async", "invocation type async").Bool(),
LogTail: invoke.Flag("log-tail", "output tail of log to STDERR").Bool(),
Qualifier: invoke.Flag("qualifier", "version or alias to invoke").String(),
}
archive := kingpin.Command("archive", "archive zip")
archiveOption := lambroll.DeployOption{
Src: archive.Flag("src", "function src dir for archive").Default(".").String(),
ExcludeFile: archive.Flag("exclude-file", "exclude file").Default(lambroll.IgnoreFilename).String(),
}
logs := kingpin.Command("logs", "tail logs using `aws logs tail` (aws-cli v2 required)")
logsOption := lambroll.LogsOption{
FunctionFilePath: function,
Since: logs.Flag("since", "From what time to begin displaying logs").Default("10m").String(),
Follow: logs.Flag("follow", "follow new logs").Default("false").Bool(),
Format: logs.Flag("format", "The format to display the logs").Default("detailed").String(),
FilterPattern: logs.Flag("filter-pattern", "The filter pattern to use").Default("").String(),
}
diff := kingpin.Command("diff", "show display diff of function.json compared with latest function")
diffOption := lambroll.DiffOption{
FunctionFilePath: function,
CodeSha256: diff.Flag("code", "diff of code sha256").Default("false").Bool(),
ExcludeFile: diff.Flag("exclude-file", "exclude file").Default(lambroll.IgnoreFilename).String(),
Src: diff.Flag("src", "function zip archive or src dir").Default(".").String(),
Ignore: diff.Flag("ignore", `ignore function elements. jq queries joined with ",". for example, ".Foo, .Bar"`).String(),
}
versions := kingpin.Command("versions", "manage function versions")
versionsOption := lambroll.VersionsOption{
FunctionFilePath: function,
Output: versions.Flag("output", "output format").Default("table").Enum("table", "json", "tsv"),
Delete: versions.Flag("delete", "delete older versions").Default("false").Bool(),
KeepVersions: versions.Flag("keep-versions", "Number of latest versions to keep. Older versions will be deleted with --delete.").Default("-1").Int(),
}
command := kingpin.Parse()
if command == "version" {
fmt.Println("lambroll", Version)
return 0
}
color.NoColor = !*colorOpt
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"debug", "info", "warn", "error"},
ModifierFuncs: []logutils.ModifierFunc{
logutils.Color(color.FgHiBlack), // debug
nil, // info
logutils.Color(color.FgYellow), // warn
logutils.Color(color.FgRed), // error
},
MinLevel: logutils.LogLevel(*logLevel),
Writer: os.Stderr,
}
log.SetOutput(filter)
app, err := lambroll.New(context.TODO(), &opt)
if err != nil {
log.Println("[error]", err)
return 1
}
ctx := context.TODO()
log.Printf("[info] lambroll %s with %s", Version, *function)
switch command {
case "init":
err = app.Init(ctx, initOption)
case "list":
err = app.List(ctx, listOption)
case "deploy":
err = app.Deploy(ctx, deployOption)
case "rollback":
err = app.Rollback(ctx, rollbackOption)
case "delete":
err = app.Delete(ctx, deleteOption)
case "invoke":
err = app.Invoke(ctx, invokeOption)
case "archive":
err = app.Archive(ctx, archiveOption)
case "logs":
err = app.Logs(ctx, logsOption)
case "diff":
err = app.Diff(ctx, diffOption)
case "versions":
err = app.Versions(ctx, versionsOption)
}
if err != nil {
log.Println("[error]", err)
return 1
}
log.Println("[info] completed")
return 0
}
*/

0 comments on commit 212fc14

Please # to comment.