mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
refactor: provide log output directly on debug
This commit is contained in:
parent
8837c127ed
commit
e0513e95b0
2
.github/ISSUE_TEMPLATE/bug.yml
vendored
2
.github/ISSUE_TEMPLATE/bug.yml
vendored
|
@ -29,7 +29,7 @@ body:
|
||||||
id: logs
|
id: logs
|
||||||
attributes:
|
attributes:
|
||||||
label: Log output
|
label: Log output
|
||||||
description: Please copy and paste the output generated by `Write-PoshDebug` (PowerShell) or `oh-my-posh --debug --shell uni --config="$POSH_THEME"` for other shells. Please copy/paste the log file's content, formatting is done automatically.
|
description: Please copy and paste the output generated by `Write-PoshDebug` (PowerShell) or `oh-my-posh --debug --shell uni --config="$POSH_THEME"` for other shells.
|
||||||
render: shell
|
render: shell
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
|
|
|
@ -128,8 +128,8 @@ func (e *engine) renderBlock(block *Block) {
|
||||||
func (e *engine) debug() string {
|
func (e *engine) debug() string {
|
||||||
var segmentTimings []*SegmentTiming
|
var segmentTimings []*SegmentTiming
|
||||||
largestSegmentNameLength := 0
|
largestSegmentNameLength := 0
|
||||||
e.write("\n\x1b[1mHere are the timings of segments in your prompt:\x1b[0m\n\n")
|
e.write(fmt.Sprintf("\n\x1b[1mVersion:\x1b[0m %s\n", Version))
|
||||||
|
e.write("\n\x1b[1mSegments:\x1b[0m\n\n")
|
||||||
// console title timing
|
// console title timing
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
consoleTitle := e.consoleTitle.getTemplateText()
|
consoleTitle := e.consoleTitle.getTemplateText()
|
||||||
|
@ -163,8 +163,8 @@ func (e *engine) debug() string {
|
||||||
segmentName := fmt.Sprintf("%s(%t)", segment.name, segment.enabled)
|
segmentName := fmt.Sprintf("%s(%t)", segment.name, segment.enabled)
|
||||||
e.write(fmt.Sprintf("%-*s - %3d ms - %s\n", largestSegmentNameLength, segmentName, duration, segment.stringValue))
|
e.write(fmt.Sprintf("%-*s - %3d ms - %s\n", largestSegmentNameLength, segmentName, duration, segment.stringValue))
|
||||||
}
|
}
|
||||||
e.write(fmt.Sprintf("\n\x1b[1mVersion:\x1b[0m %s\n", Version))
|
e.write("\n\x1b[1mLogs:\x1b[0m\n\n")
|
||||||
e.write(fmt.Sprintf("\x1b[1mLog:\x1b[0m %s/oh-my-posh.log\n\n", e.env.homeDir()))
|
e.write(e.env.logs())
|
||||||
return e.string()
|
return e.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ type environmentInfo interface {
|
||||||
getCachePath() string
|
getCachePath() string
|
||||||
cache() cache
|
cache() cache
|
||||||
close()
|
close()
|
||||||
|
logs() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type commandCache struct {
|
type commandCache struct {
|
||||||
|
@ -115,40 +116,32 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type tracer interface {
|
type tracer interface {
|
||||||
init(home string)
|
init()
|
||||||
close()
|
string() string
|
||||||
trace(start time.Time, function string, args ...string)
|
trace(start time.Time, function string, args ...string)
|
||||||
log(lt logType, function, message string)
|
log(lt logType, function, message string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type fileTracer struct {
|
type logTracer struct {
|
||||||
file *os.File
|
builder strings.Builder
|
||||||
debug bool
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fileTracer) init(home string) {
|
func (t *logTracer) init() {
|
||||||
if !t.debug {
|
if !t.debug {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var err error
|
log.SetOutput(&t.builder)
|
||||||
fileName := home + "/oh-my-posh.log"
|
|
||||||
t.file, err = os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("error opening file: %v", err)
|
|
||||||
}
|
|
||||||
log.SetOutput(t.file)
|
|
||||||
log.Println("#### start oh-my-posh run ####")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fileTracer) close() {
|
func (t *logTracer) string() string {
|
||||||
if !t.debug {
|
if !t.debug {
|
||||||
return
|
return ""
|
||||||
}
|
}
|
||||||
log.Println("#### end oh-my-posh run ####")
|
return t.builder.String()
|
||||||
_ = t.file.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fileTracer) trace(start time.Time, function string, args ...string) {
|
func (t *logTracer) trace(start time.Time, function string, args ...string) {
|
||||||
if !t.debug {
|
if !t.debug {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -157,7 +150,7 @@ func (t *fileTracer) trace(start time.Time, function string, args ...string) {
|
||||||
log.Println(trace)
|
log.Println(trace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *fileTracer) log(lt logType, function, message string) {
|
func (t *logTracer) log(lt logType, function, message string) {
|
||||||
if !t.debug {
|
if !t.debug {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -178,10 +171,10 @@ func (env *environment) init(args *args) {
|
||||||
env.cmdCache = &commandCache{
|
env.cmdCache = &commandCache{
|
||||||
commands: newConcurrentMap(),
|
commands: newConcurrentMap(),
|
||||||
}
|
}
|
||||||
tracer := &fileTracer{
|
tracer := &logTracer{
|
||||||
debug: *args.Debug,
|
debug: *args.Debug,
|
||||||
}
|
}
|
||||||
tracer.init(env.homeDir())
|
tracer.init()
|
||||||
env.tracer = tracer
|
env.tracer = tracer
|
||||||
env.fileCache = &fileCache{}
|
env.fileCache = &fileCache{}
|
||||||
env.fileCache.init(env.getCachePath())
|
env.fileCache.init(env.getCachePath())
|
||||||
|
@ -531,7 +524,10 @@ func (env *environment) cache() cache {
|
||||||
|
|
||||||
func (env *environment) close() {
|
func (env *environment) close() {
|
||||||
env.fileCache.close()
|
env.fileCache.close()
|
||||||
env.tracer.close()
|
}
|
||||||
|
|
||||||
|
func (env *environment) logs() string {
|
||||||
|
return env.tracer.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanHostName(hostName string) string {
|
func cleanHostName(hostName string) string {
|
||||||
|
|
|
@ -13,21 +13,30 @@ type MockedTracer struct {
|
||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
// close provides a mock function with given fields:
|
// init provides a mock function with given fields:
|
||||||
func (_m *MockedTracer) close() {
|
func (_m *MockedTracer) init() {
|
||||||
_m.Called()
|
_m.Called()
|
||||||
}
|
}
|
||||||
|
|
||||||
// init provides a mock function with given fields: home
|
|
||||||
func (_m *MockedTracer) init(home string) {
|
|
||||||
_m.Called(home)
|
|
||||||
}
|
|
||||||
|
|
||||||
// log provides a mock function with given fields: lt, function, message
|
// log provides a mock function with given fields: lt, function, message
|
||||||
func (_m *MockedTracer) log(lt logType, function, message string) {
|
func (_m *MockedTracer) log(lt logType, function, message string) {
|
||||||
_m.Called(lt, function, message)
|
_m.Called(lt, function, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// string provides a mock function with given fields:
|
||||||
|
func (_m *MockedTracer) string() string {
|
||||||
|
ret := _m.Called()
|
||||||
|
|
||||||
|
var r0 string
|
||||||
|
if rf, ok := ret.Get(0).(func() string); ok {
|
||||||
|
r0 = rf()
|
||||||
|
} else {
|
||||||
|
r0 = ret.Get(0).(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0
|
||||||
|
}
|
||||||
|
|
||||||
// trace provides a mock function with given fields: start, function, args
|
// trace provides a mock function with given fields: start, function, args
|
||||||
func (_m *MockedTracer) trace(start time.Time, function string, args ...string) {
|
func (_m *MockedTracer) trace(start time.Time, function string, args ...string) {
|
||||||
_va := make([]interface{}, len(args))
|
_va := make([]interface{}, len(args))
|
||||||
|
|
|
@ -168,6 +168,11 @@ func (env *MockedEnvironment) close() {
|
||||||
_ = env.Called(nil)
|
_ = env.Called(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (env *MockedEnvironment) logs() string {
|
||||||
|
args := env.Called(nil)
|
||||||
|
return args.String(0)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
homeBill = "/home/bill"
|
homeBill = "/home/bill"
|
||||||
homeJan = "/usr/home/jan"
|
homeJan = "/usr/home/jan"
|
||||||
|
|
Loading…
Reference in a new issue