Skip to content

Commit 6614323

Browse files
committed
logfile output other than stdout
1 parent f4534db commit 6614323

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ the message.
422422
"source": "source_identifier",
423423
"to": "originator_identifier",
424424
"command": {
425-
"id": "identifier (use the identifier from the request",
425+
"id": "identifier (use the identifier from the request)",
426426
"action": "info",
427427
"type": "user",
428428
"map": {"field1": "data1", "field2": "data2"}
@@ -441,7 +441,7 @@ the message.
441441
"id": "identifier",
442442
"action": "room_request",
443443
"type": "name / id",
444-
"data": "room
444+
"data": "room"
445445
}
446446
}
447447
```
@@ -456,11 +456,17 @@ the message.
456456
"id": "identifier",
457457
"action": "info",
458458
"type": "room",
459+
"error": "Error message (if request fails)",
459460
"map": {"field1": "data1", "field2": "data2"}
460461
}
461462
}
462463
```
463464

465+
**Note** "error" field is only send back when error occurs. Information
466+
requester should first evaluate whether "error" field is empty before
467+
proceeding. If "error" field contains value, the map part of the information
468+
response should be considered invalided and discarded.
469+
464470
**Note** Both user and room information request are neither validated nor
465471
evaluated by Priscilla server, it's simply forwarded to the target adapter. The
466472
information response from the adapter, is also directly forwarded to the

commandQuery.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type commandBlock struct {
1515
Type string `json:"type"`
1616
Time int64 `json:"time,omitempty"`
1717
Data string `json:"data,omitempty"`
18+
Error string `json"error,omitempty"`
1819
Array []string `json:"array,omitempty"`
1920
Options []string `json:"options,omitempty"`
2021
Map map[string]string `json:"map,omitempty"`

priscilla.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,49 @@ var unhandledAResponders *list.List
7979
var subRegex *regexp.Regexp
8080
var help *list.List
8181

82+
var version, build string
83+
8284
func main() {
8385
confFile := flag.String("conf", "", "Conf files, you know, conf files")
8486
loglevel :=
8587
flag.String("loglevel", "warn", "log level: debug/info/warn/error")
88+
logfile := flag.String("log", "STDOUT", "Log file")
89+
showversion := flag.Bool("version", false, "show version and exit")
8690

8791
flag.Parse()
8892

93+
if *showversion {
94+
if version == "" {
95+
fmt.Println("Version: development")
96+
} else {
97+
fmt.Println("Version:", version)
98+
}
99+
100+
if build == "" {
101+
fmt.Println("Build: development")
102+
} else {
103+
fmt.Println("Build:", build)
104+
}
105+
os.Exit(0)
106+
}
107+
89108
var err error
90109

91-
logger, err = prislog.NewLogger(os.Stdout, *loglevel)
110+
var logwriter *os.File
111+
112+
if *logfile == "STDOUT" {
113+
logwriter = os.Stdout
114+
} else {
115+
logwriter, err = os.OpenFile(*logfile,
116+
os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
117+
if err != nil {
118+
fmt.Println("Unable to write to log file", *logfile, ":", err)
119+
os.Exit(1)
120+
}
121+
defer logwriter.Close()
122+
}
123+
124+
logger, err = prislog.NewLogger(logwriter, *loglevel)
92125

93126
if err != nil {
94127
fmt.Println("Error initializing logger: ", err)
@@ -222,13 +255,15 @@ func main() {
222255
}
223256

224257
if conf.Port == 0 {
225-
logger.Error.Fatal("No port specified!")
258+
logger.Warn.Println("No port specified, using default: 4517")
259+
conf.Port = 4517
226260
}
227261

228262
// Prefix need to be free of excess spaces
229263
conf.Prefix = strings.Trim(conf.Prefix, " ")
230264
if len(conf.Prefix) < 1 {
231-
logger.Error.Fatal("Prefix is empty")
265+
logger.Warn.Println("No prefix specified, using default: pris")
266+
conf.Prefix = "pris"
232267
}
233268
conf.Prefix += " "
234269
conf.prefixLen = len(conf.Prefix)

0 commit comments

Comments
 (0)