forked from gonicus/gofaxip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Markus Lindenberg
committed
May 8, 2014
1 parent
25911b9
commit 24ba469
Showing
8 changed files
with
300 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package gofaxlib | ||
|
||
import ( | ||
"fmt" | ||
"gofaxlib/logger" | ||
"path/filepath" | ||
) | ||
|
||
const ( | ||
LOG_DIR = "log" | ||
COMMID_FORMAT = "%08d" | ||
LOG_FILE_FORMAT = "c%s" | ||
) | ||
|
||
type SessionLogger interface { | ||
CommSeq() uint64 | ||
CommId() string | ||
Logfile() string | ||
|
||
Log(v ...interface{}) | ||
} | ||
|
||
type hylasessionlog struct { | ||
commseq uint64 | ||
commid string | ||
|
||
logfile string | ||
} | ||
|
||
func NewSessionLogger() (SessionLogger, error) { | ||
// Fetch commid and log file name | ||
commseq, err := GetSeqFor(LOG_DIR) | ||
if err != nil { | ||
return nil, err | ||
} | ||
commid := fmt.Sprintf(COMMID_FORMAT, commseq) | ||
logfile := filepath.Join(LOG_DIR, fmt.Sprintf(LOG_FILE_FORMAT, commid)) | ||
|
||
l := &hylasessionlog{ | ||
commseq: commseq, | ||
commid: commid, | ||
logfile: logfile, | ||
} | ||
|
||
return l, nil | ||
} | ||
|
||
func (h *hylasessionlog) Log(v ...interface{}) { | ||
logger.Logger.Println(v...) | ||
if err := AppendLog(h.logfile, v...); err != nil { | ||
logger.Logger.Print(err) | ||
} | ||
} | ||
|
||
func (h *hylasessionlog) CommSeq() uint64 { | ||
return h.commseq | ||
} | ||
|
||
func (h *hylasessionlog) CommId() string { | ||
return h.commid | ||
} | ||
|
||
func (h *hylasessionlog) Logfile() string { | ||
return h.logfile | ||
} |
Oops, something went wrong.