Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalClient
Commits
d9d90a76
Commit
d9d90a76
authored
Mar 26, 2020
by
lukas.burgey
Browse files
Add indentation to the logs
parent
dfce6039
Changes
4
Show whitespace changes
Inline
Side-by-side
indent/indent.go
0 → 100644
View file @
d9d90a76
package
indent
import
(
"bytes"
"encoding/json"
)
var
(
prefix
=
""
indent
=
" "
)
// Indent indents a json string if possible
// if unsuccessful it just returns src
func
Indent
(
src
[]
byte
)
(
ds
[]
byte
)
{
buf
:=
new
(
bytes
.
Buffer
)
err
:=
json
.
Indent
(
buf
,
src
,
prefix
,
indent
)
if
err
!=
nil
{
return
src
}
ds
=
buf
.
Bytes
()
return
}
sink/script/script.go
View file @
d9d90a76
...
...
@@ -14,6 +14,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config"
deps
"git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
scripts
"git.scc.kit.edu/feudal/feudalScripts/v2"
)
...
...
@@ -121,43 +122,31 @@ func (sink *Sink) handleDep(dep deps.Dep) (output scripts.Output, err error) {
stdin
.
Write
(
iBytes
)
stdin
.
Close
()
// decode json output
var
outputBytes
,
logOutputBytes
[]
byte
outputBytes
,
err
=
ioutil
.
ReadAll
(
stdout
)
if
err
!=
nil
{
return
}
// read stdout / stderr
var
stdoutBytes
,
stderrBytes
[]
byte
logOutp
utBytes
,
err
=
ioutil
.
ReadAll
(
std
err
)
stdo
utBytes
,
err
=
ioutil
.
ReadAll
(
std
out
)
if
err
!=
nil
{
return
}
if
sink
.
Config
.
Debug
.
Scripts
{
if
len
(
logOutputBytes
)
>
0
{
dep
.
Log
(
"Logs:
\n
%s"
,
logOutputBytes
)
stderrBytes
,
_
=
ioutil
.
ReadAll
(
stderr
)
if
sink
.
Config
.
Debug
.
Scripts
&&
len
(
stderrBytes
)
>
0
{
dep
.
Log
(
"Logs:
\n
%s"
,
stderrBytes
)
dep
.
Log
(
"End of Logs"
)
}
}
// waits for command execution and pipe reading
err
=
cmd
.
Wait
()
if
err
!=
nil
{
return
}
if
sink
.
Config
.
Debug
.
Scripts
{
var
indented
=
new
(
bytes
.
Buffer
)
err
=
json
.
Indent
(
indented
,
outputBytes
,
" "
,
" "
)
if
err
!=
nil
{
dep
.
Log
(
"Output (unable to indent: %s):
\n
%s"
,
err
,
outputBytes
)
}
else
{
dep
.
Log
(
"Output:
\n
%s"
,
indented
.
String
())
}
dep
.
Log
(
"Output: %s"
,
indent
.
Indent
(
stdoutBytes
))
}
err
=
json
.
Unmarshal
(
outp
utBytes
,
&
output
)
err
=
json
.
Unmarshal
(
stdo
utBytes
,
&
output
)
if
err
!=
nil
{
if
len
(
outputBytes
)
>
0
{
dep
.
Log
(
"Raw output: %s"
,
outputBytes
)
}
return
}
...
...
source/amqp/amqp.go
View file @
d9d90a76
package
amqp
import
(
"bytes"
"encoding/json"
"fmt"
"log"
...
...
@@ -9,6 +8,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config"
deps
"git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
"github.com/streadway/amqp"
)
...
...
@@ -119,12 +119,7 @@ func (src *Source) connect() (deliveries <-chan amqp.Delivery, closed <-chan *am
func
(
src
*
Source
)
consume
(
sink
chan
<-
deps
.
Dep
,
deliveries
<-
chan
amqp
.
Delivery
)
{
consumeWrapper
:=
func
(
del
amqp
.
Delivery
)
{
if
src
.
Config
.
Debug
.
Backend
{
indented
:=
new
(
bytes
.
Buffer
)
if
err
:=
json
.
Indent
(
indented
,
del
.
Body
,
" "
,
" "
);
err
!=
nil
{
log
.
Printf
(
"[AMQP] Received (unable to indent: %v):
\n
%s"
,
err
,
del
.
Body
)
}
else
{
log
.
Printf
(
"[AMQP] Received:
\n
%s"
,
indented
)
}
log
.
Printf
(
"[AMQP] Received: %s"
,
indent
.
Indent
(
del
.
Body
))
}
var
newDep
deps
.
Dep
...
...
source/rest/rest.go
View file @
d9d90a76
package
rest
import
(
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
...
...
@@ -11,6 +10,7 @@ import (
"git.scc.kit.edu/feudal/feudalClient/config"
deps
"git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/indent"
)
type
(
...
...
@@ -70,13 +70,7 @@ func (src Source) fetchDeps(sink chan<- deps.Dep) (err error) {
}
if
src
.
Config
.
Debug
.
Backend
{
indented
:=
new
(
bytes
.
Buffer
)
indentErr
:=
json
.
Indent
(
indented
,
body
,
""
,
" "
)
if
indentErr
!=
nil
{
log
.
Printf
(
"[HTTP] Fetched (unable to indent: %v):
\n
%s"
,
err
,
body
)
}
else
{
log
.
Printf
(
"[HTTP] Fetched:
\n
%s"
,
indented
)
}
log
.
Printf
(
"[HTTP] Fetched: %s"
,
indent
.
Indent
(
body
))
}
go
func
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment