Skip to content

Commit

Permalink
Merge pull request #41 from mageddo/feature/40
Browse files Browse the repository at this point in the history
#40 Remove Unnecessary method name in logs
  • Loading branch information
mageddo authored Sep 30, 2017
2 parents 0799e03 + 26239d4 commit 5f473fb
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 53 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
.gradle/
*.orig
*.tmp


conf/config.json
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.7
2.1.8
2 changes: 1 addition & 1 deletion conf/SetMachineDnsServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (hd *setMachineDNSServerHandler) process(line string, entryType DnsEntry) *

switch entryType {
case PROXY:
LOGGER.Infof("m=SetMachineDNSServer, status=found-dns-proxy-entry")
LOGGER.Infof("status=found-dns-proxy-entry")
v := getDNSLine(hd.serverIP)
return &v
case SERVER:
Expand Down
22 changes: 11 additions & 11 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func GetString(value, defaultValue string) string {
}

func RestoreResolvconfToDefault() error {
LOGGER.Infof("m=RestoreResolvconfToDefault, status=begin")
LOGGER.Infof("status=begin")
hd := newDNSServerCleanerHandler()
err := ProcessResolvconf(hd)
LOGGER.Infof("m=RestoreResolvconfToDefault, status=success, err=%v", err)
LOGGER.Infof("status=success, err=%v", err)
return err
}

Expand All @@ -99,7 +99,7 @@ func SetMachineDNSServer(serverIP string) error {
func ProcessResolvconf( handler DnsHandler ) error {

var newResolvConfBuff bytes.Buffer
LOGGER.Infof("m=ProcessResolvconf, status=begin")
LOGGER.Infof("status=begin")

resolvconf := getResolvConf()
fileRead, err := os.Open(resolvconf)
Expand All @@ -112,7 +112,7 @@ func ProcessResolvconf( handler DnsHandler ) error {
hasContent = false
foundDnsProxyEntry = false
)
LOGGER.Infof("m=ProcessResolvconf, status=open-conf-file, file=%s", fileRead.Name())
LOGGER.Infof("status=open-conf-file, file=%s", fileRead.Name())
scanner := bufio.NewScanner(fileRead)
for scanner.Scan() {
line := scanner.Text()
Expand All @@ -121,7 +121,7 @@ func ProcessResolvconf( handler DnsHandler ) error {
if entryType == PROXY {
foundDnsProxyEntry = true
}
LOGGER.Debugf("m=ProcessResolvconf, status=readline, line=%s, type=%s", line, entryType)
LOGGER.Debugf("status=readline, line=%s, type=%s", line, entryType)
if r := handler.process(line, entryType); r != nil {
newResolvConfBuff.WriteString(*r)
newResolvConfBuff.WriteByte('\n')
Expand All @@ -138,7 +138,7 @@ func ProcessResolvconf( handler DnsHandler ) error {
if err != nil {
return err
}
LOGGER.Infof("m=ProcessResolvconf, status=success, buffLength=%d", length)
LOGGER.Infof("status=success, buffLength=%d", length)
return nil
}

Expand Down Expand Up @@ -174,7 +174,7 @@ func SetCurrentDNSServerToMachineAndLockIt() error {
func SetCurrentDNSServerToMachine() error {

ip, err := getCurrentIpAddress()
LOGGER.Infof("m=SetCurrentDNSServerToMachine, status=begin, ip=%s, err=%v", ip, err)
LOGGER.Infof("status=begin, ip=%s, err=%v", ip, err)
if err != nil {
return err
}
Expand All @@ -191,25 +191,25 @@ func UnlockResolvConf() error {

func LockFile(lock bool, file string) error {

LOGGER.Infof("m=Lockfile, status=begin, lock=%t, file=%s", lock, file)
LOGGER.Infof("status=begin, lock=%t, file=%s", lock, file)
flag := "-i"
if lock {
flag = "+i"
}
cmd := exec.Command("chattr", flag, file)
err := cmd.Run()
if err != nil {
LOGGER.Warningf("m=Lockfile, status=error-at-execute, lock=%t, file=%s, err=%v", lock, file, err)
LOGGER.Warningf("status=error-at-execute, lock=%t, file=%s, err=%v", lock, file, err)
return err
}
//bytes, err := cmd.CombinedOutput()

status := cmd.ProcessState.Sys().(syscall.WaitStatus)
if status.ExitStatus() != 0 {
LOGGER.Warningf("m=Lockfile, status=bad-exit-code, lock=%t, file=%s", lock, file)
LOGGER.Warningf("status=bad-exit-code, lock=%t, file=%s", lock, file)
return errors.New(fmt.Sprintf("Failed to lock file %d", status.ExitStatus()))
}
LOGGER.Infof("m=Lockfile, status=success, lock=%t, file=%s", lock, file)
LOGGER.Infof("status=success, lock=%t, file=%s", lock, file)
return nil

}
Expand Down
20 changes: 20 additions & 0 deletions conf/config.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"remoteDnsServers": [],
"envs": [
{
"name": "",
"hostnames": [
{
"id": 1,
"hostname": "github.com",
"ip": [192, 168, 0, 1],
"ttl": 255
}
]
}
],
"activeEnv": "",
"lastId": 1,
"webServerPort": 0,
"dnsServerPort": 0
}
8 changes: 4 additions & 4 deletions controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ func MapReq(method Method, path string, fn func(context.Context, http.ResponseWr
ctx := log.NewContext()
logger := log.NewLog(ctx)

logger.Debugf("m=MapReq, status=begin, matched=%t, url=%s, method=%s", matched, urlPath, r.Method)
logger.Debugf("status=begin, matched=%t, url=%s, method=%s", matched, urlPath, r.Method)
if matched {
function := maps[urlPath][r.Method]
function(ctx, w, r, urlPath)
logger.Debugf("m=MapReq, status=success, url=%s %s", r.Method, urlPath)
logger.Debugf("status=success, url=%s %s", r.Method, urlPath)
}else{
logger.Debugf("m=MapReq, status=not-found, url=%s %s", r.Method, urlPath)
logger.Debugf("status=not-found, url=%s %s", r.Method, urlPath)
http.NotFound(w, r)
}

})
}
LOGGER.Debugf("m=MapReq, status=mapping, url=%s %s", method, path)
LOGGER.Debugf("status=mapping, url=%s %s", method, path)
maps[path][string(method)] = fn

}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- TERM=xterm
- GOPATH=/app
- MG_WORK_DIR=/app/src/github.com/mageddo/dns-proxy-server
hostname: gocompiler.dev
hostname: dns-proxy-server.dev
network_mode: bridge


Expand Down
2 changes: 1 addition & 1 deletion events/docker/DockerEvents.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func putHostnames(ctx context.Context, hostnames []string, inspect types.Contain
return errors.New(err)
}
}
logger.Debugf("m=putHostnames, host=%s, ip=%s", host, ip)
logger.Debugf("host=%s, ip=%s", host, ip)
cache[host] = ip
}
return nil
Expand Down
34 changes: 17 additions & 17 deletions events/local/LocalEvents.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ func LoadConfiguration(ctx context.Context){
func SaveConfiguration(ctx context.Context, c *LocalConfiguration) {
logger := log.NewLog(ctx)

logger.Infof("m=SaveConfiguration, status=begin, time=%s", time.Now())
logger.Infof("status=begin, time=%s", time.Now())
if len(c.Envs) == 0 {
c.Envs = NewEmptyEnv()
}

logger.Infof("m=SaveConfiguration, status=save")
logger.Infof("status=save")
f, err := os.OpenFile(confPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
defer func(){
f.Close()
Expand All @@ -90,7 +90,7 @@ func SaveConfiguration(ctx context.Context, c *LocalConfiguration) {
logger.Errorf("status=error-to-encode, error=%v", err)
}

logger.Infof("m=SaveConfiguration, status=success")
logger.Infof("status=success")

}

Expand Down Expand Up @@ -147,7 +147,7 @@ func (lc *LocalConfiguration) GetEnv(envName string) (*EnvVo, int) {
func (foundEnv *EnvVo) AddHostname(ctx context.Context, hostname *HostnameVo) error {

logger := log.NewLog(ctx)
logger.Infof("m=AddHostnameToEnv, status=begin, env=%s, hostname=%+v", foundEnv.Name, hostname)
logger.Infof("status=begin, env=%s, hostname=%+v", foundEnv.Name, hostname)
if foundEnv == nil {
return errors.New("env not found")
}
Expand Down Expand Up @@ -211,36 +211,36 @@ func(env *EnvVo) GetHostnameById(id int) (*HostnameVo, int) {

func (lc *LocalConfiguration) AddEnv(ctx context.Context, env EnvVo) error {
logger := log.NewLog(ctx)
logger.Infof("m=AddEnv, status=begin, env=%s", env.Name)
logger.Infof("status=begin, env=%s", env.Name)
foundEnv, _ := lc.GetEnv(env.Name)
if foundEnv != nil {
return errors.New(fmt.Sprintf("The '%s' env already exists", env.Name))
}
lc.Envs = append(lc.Envs, env)
SaveConfiguration(ctx, lc)
logger.Infof("m=AddEnv, status=success, env=%s", env.Name)
logger.Infof("status=success, env=%s", env.Name)
return nil
}

func (lc *LocalConfiguration) RemoveEnvByName(ctx context.Context, name string) error {
logger := log.NewLog(ctx)
logger.Infof("m=RemoveEnvByName, status=begin, env=%s", name)
logger.Infof("status=begin, env=%s", name)
env, i := lc.GetEnv(name)
if env == nil {
return errors.New(fmt.Sprintf("The env '%s' was not found", name))
}
lc.RemoveEnv(ctx, i)
SaveConfiguration(ctx,lc)
logger.Infof("m=RemoveEnvByName, status=success, env=%s", name)
logger.Infof("status=success, env=%s", name)
return nil
}

func (lc *LocalConfiguration) RemoveEnv(ctx context.Context, index int){
logger := log.NewLog(ctx)
logger.Infof("m=RemoveEnv, status=begin, index=%d", index)
logger.Infof("status=begin, index=%d", index)
lc.Envs = append(lc.Envs[:index], lc.Envs[index+1:]...)
SaveConfiguration(ctx,lc)
logger.Infof("m=RemoveEnv, status=success, index=%d", index)
logger.Infof("status=success, index=%d", index)
}

func (lc *LocalConfiguration) AddDns(ctx context.Context, dns [4]byte){
Expand Down Expand Up @@ -309,7 +309,7 @@ func (env *EnvVo) UpdateHostname(hostname HostnameVo) error {

func (lc *LocalConfiguration) RemoveHostnameByEnvAndHostname(ctx context.Context, envName string, hostname string) error {
logger := log.NewLog(ctx)
logger.Infof("m=RemoveHostnameByEnvAndHostname, status=begin, envName=%s, hostname=%s", envName, hostname)
logger.Infof("status=begin, envName=%s, hostname=%s", envName, hostname)
env, envIndex := lc.GetEnv(envName)
if envIndex == -1 {
return errors.New("env not found")
Expand All @@ -319,32 +319,32 @@ func (lc *LocalConfiguration) RemoveHostnameByEnvAndHostname(ctx context.Context
return errors.New("hostname not found")
}
lc.RemoveHostname(ctx, envIndex, hostIndex)
logger.Infof("m=RemoveHostnameByEnvAndHostname, status=success, envName=%s, hostname=%s", envName, hostname)
logger.Infof("status=success, envName=%s, hostname=%s", envName, hostname)
return nil
}

func (lc *LocalConfiguration) RemoveHostname(ctx context.Context, envIndex int, hostIndex int){

logger := log.NewLog(ctx)
logger.Infof("m=RemoveHostname, status=begin, envIndex=%d, hostIndex=%d", envIndex, hostIndex)
logger.Infof("status=begin, envIndex=%d, hostIndex=%d", envIndex, hostIndex)
env := &lc.Envs[envIndex];
(*env).Hostnames = append((*env).Hostnames[:hostIndex], (*env).Hostnames[hostIndex+1:]...)
SaveConfiguration(ctx, lc)
logger.Infof("m=RemoveHostname, status=success, envIndex=%d, hostIndex=%d", envIndex, hostIndex)
logger.Infof("status=success, envIndex=%d, hostIndex=%d", envIndex, hostIndex)

}

func (lc *LocalConfiguration) SetActiveEnv(ctx context.Context, env EnvVo) error {
logger := log.NewLog(ctx)
logger.Infof("m=SetActiveEnv, status=begin, envActive=%s", env.Name)
logger.Infof("status=begin, envActive=%s", env.Name)
foundEnv, _ := lc.GetEnv(env.Name)
if foundEnv == nil {
logger.Warningf("m=SetActiveEnv, status=env-not-found, envName=%s", env.Name)
logger.Warningf("status=env-not-found, envName=%s", env.Name)
return errors.New("Env not found: " + env.Name)
}
lc.ActiveEnv = env.Name
SaveConfiguration(ctx, lc)
logger.Infof("m=SetActiveEnv, status=success")
logger.Infof("status=success")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion proxy/DockerDnsSolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (DockerDnsSolver) Solve(ctx context.Context, question dns.Question) (*dns.M

logger := log.NewLog(ctx)
key := question.Name[:len(question.Name)-1]
logger.Debugf("m=solve, status=solved-key, solver=docker, hostname=%s, ip=%s", key, docker.Get(key))
logger.Debugf("status=solved-key, solver=docker, hostname=%s, ip=%s", key, docker.Get(key))
if docker.ContainsKey(key) {

ip := docker.Get(key)
Expand Down
2 changes: 1 addition & 1 deletion proxy/LocalDnsSolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (LocalDnsSolver) Solve(ctx context.Context, question dns.Question) (*dns.Ms

m := new(dns.Msg)
m.Answer = append(m.Answer, rr)
LOGGER.Infof("m=solve, status=success, solver=local")
LOGGER.Infof("status=success, solver=local")
return m, nil
}
return nil, errors.New("hostname not found")
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (sc *Service) SetupFor(servicePath, serviceName string, script *Script) err
sc.logger.Fatalf("status=fatal-install-service, service=chkconfig, msg=%s", err.Error())
}
} else { // not known
sc.logger.Warningf("m=ConfigSetupService, status=impossible to setup to start at boot")
sc.logger.Warningf("status=impossible to setup to start at boot")
}

out, err, _ := utils.Exec("service", serviceName, "stop")
Expand Down
6 changes: 3 additions & 3 deletions test/dnsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func handleReflect(respWriter dns.ResponseWriter, reqMsg *dns.Msg) {
defer func() {
err := recover()
if err != nil {
LOGGER.Errorf("M=handleReflect, status=error, error=%v", err)
LOGGER.Errorf("status=error, error=%v", err)
}
}()

Expand All @@ -67,7 +67,7 @@ func handleReflect(respWriter dns.ResponseWriter, reqMsg *dns.Msg) {
questionName = "null"
}

LOGGER.Infof("m=handleReflect, questions=%d, 1stQuestion=%s", len(reqMsg.Question), questionName)
LOGGER.Infof("questions=%d, 1stQuestion=%s", len(reqMsg.Question), questionName)

resp := SolveName(questionName)
resp.SetReply(reqMsg)
Expand All @@ -79,7 +79,7 @@ func handleReflect(respWriter dns.ResponseWriter, reqMsg *dns.Msg) {
firstAnswer = resp.Answer[0]
}

LOGGER.Infof("m=handleReflect, resp=%v", firstAnswer)
LOGGER.Infof("resp=%v", firstAnswer)
respWriter.WriteMsg(resp)

}
Expand Down
4 changes: 2 additions & 2 deletions test/maintest.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ func (p *Person) addChild(name string) {
func (p *Person) addChildByPointer(name string) {
childs := p.getChilds()
newChilds := append(*childs, name)
fmt.Printf("m=addChildByPointer, childs=%p, newChilds=%p\n", childs, &newChilds)
fmt.Printf("childs=%p, newChilds=%p\n", childs, &newChilds)
childs = &newChilds
}
}
8 changes: 4 additions & 4 deletions utils/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (

func Exec(cmd string, args ...string) ( out []byte, err error, exitCode int ){

LOGGER.Infof("m=Exec, cmd=%s, args=%v", cmd, args)
LOGGER.Infof("cmd=%s, args=%v", cmd, args)

execution := exec.Command(cmd, args...)
// ja chama o run dentro dele
out, err = execution.CombinedOutput()

if err != nil {
LOGGER.Infof("m=Exec, status=error, type=%v, err=%v", reflect.TypeOf(err), err)
LOGGER.Infof("status=error, type=%v, err=%v", reflect.TypeOf(err), err)
if exitError, ok := err.(*exec.ExitError); ok {
exitCode = exitError.Sys().(syscall.WaitStatus).ExitStatus()
return
Expand All @@ -29,10 +29,10 @@ func Exec(cmd string, args ...string) ( out []byte, err error, exitCode int ){
}

if exitCode != 0 {
LOGGER.Warningf("m=Exec, status=bad-exit-code, status=%d", exitCode)
LOGGER.Warningf("status=bad-exit-code, status=%d", exitCode)
return
}
LOGGER.Infof("m=Exec, status=success, cmd=%s", cmd)
LOGGER.Infof("status=success, cmd=%s", cmd)
return
}

Expand Down
Loading

0 comments on commit 5f473fb

Please sign in to comment.