summaryrefslogtreecommitdiff
path: root/obfs4proxy
diff options
context:
space:
mode:
authorYawning Angel <yawning@torproject.org>2014-09-03 11:55:16 +0000
committerYawning Angel <yawning@torproject.org>2014-09-03 11:55:16 +0000
commitfb13cf124149ebb94f400f718c9ae22dda341bdd (patch)
tree3d56a52929c8bdad7b68bff14c5c0ac88eb6455a /obfs4proxy
parent79e94103d6bf7685c78e991f0d1b93b0eecefa3d (diff)
Add a prolog/epilog to the logging that always gets logged.
The prolog prints the version as soon as logging is enabled, but before the pluggable transport configuration is done. The epilog is printed as the code returns from main, as long as either client or server pt configuration succeded.
Diffstat (limited to 'obfs4proxy')
-rw-r--r--obfs4proxy/log.go7
-rw-r--r--obfs4proxy/obfs4proxy.go14
2 files changed, 15 insertions, 6 deletions
diff --git a/obfs4proxy/log.go b/obfs4proxy/log.go
index 22f345c..5440596 100644
--- a/obfs4proxy/log.go
+++ b/obfs4proxy/log.go
@@ -41,6 +41,13 @@ const (
var logLevel = levelInfo
+func noticef(format string, a ...interface{}) {
+ if enableLogging {
+ msg := fmt.Sprintf(format, a...)
+ log.Print("[NOTICE]: " + msg)
+ }
+}
+
func errorf(format string, a ...interface{}) {
if enableLogging && logLevel >= levelError {
msg := fmt.Sprintf(format, a...)
diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go
index 7e8aad0..cf8043a 100644
--- a/obfs4proxy/obfs4proxy.go
+++ b/obfs4proxy/obfs4proxy.go
@@ -383,9 +383,8 @@ func ptInitializeLogging(enable bool) error {
return nil
}
-func version() {
- fmt.Printf("obfs4proxy-%s\n", obfs4proxyVersion)
- os.Exit(0)
+func getVersion() string {
+ return fmt.Sprintf("obfs4proxy-%s", obfs4proxyVersion)
}
func main() {
@@ -398,7 +397,8 @@ func main() {
flag.Parse()
if *showVer {
- version()
+ fmt.Printf("%s\n", getVersion())
+ os.Exit(0)
}
if err := setLogLevel(*logLevelStr); err != nil {
log.Fatalf("[ERROR]: failed to set log level: %s", err)
@@ -418,6 +418,8 @@ func main() {
}
if err = ptInitializeLogging(enableLogging); err != nil {
log.Fatalf("[ERROR]: %s - failed to initialize logging", execName)
+ } else {
+ noticef("%s - launched", getVersion())
}
if isClient {
infof("%s - initializing client transport listeners", execName)
@@ -432,9 +434,9 @@ func main() {
os.Exit(-1)
}
- infof("%s - launched and accepting connections", execName)
+ infof("%s - accepting connections", execName)
defer func() {
- infof("%s - terminated", execName)
+ noticef("%s - terminated", execName)
}()
// At this point, the pt config protocol is finished, and incoming