Last active
September 23, 2017 15:02
-
-
Save tj/a96740cd614179fdd3d8ae7dc17610cc to your computer and use it in GitHub Desktop.
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
package main | |
func main() { | |
log := NewLogger() | |
log.Info("Foo") | |
log.Info("Bar") | |
log.Error("Boom") | |
} | |
func NewLogger() Logger { | |
return Logger{ | |
prefix: "==> ", | |
} | |
} | |
type Logger struct { | |
prefix string | |
} | |
// Info level log message. | |
func (l *Logger) Info(msg string) { | |
l.log("INFO", msg) | |
} | |
// Error level log message. | |
func (l *Logger) Error(msg string) { | |
l.log("ERROR", msg) | |
} | |
// log helper. | |
func (l *Logger) log(level, msg string) { | |
println(l.prefix + level + " " + msg) | |
} |
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
// Package main. | |
const main = (function(){ | |
const print = console.log | |
const println = console.log | |
function main() { | |
let log = NewLogger() | |
log.Info("Foo") | |
log.Info("Bar") | |
log.Error("Boom") | |
} | |
function NewLogger() { | |
return new Logger({ | |
prefix: "==> " | |
}) | |
} | |
function Logger({ prefix }) { | |
this.prefix = prefix | |
} | |
Logger.prototype.Info = function(msg) { | |
const l = this | |
l.log("INFO", msg) | |
} | |
Logger.prototype.Error = function(msg) { | |
const l = this | |
l.log("ERROR", msg) | |
} | |
Logger.prototype.log = function(level, msg) { | |
const l = this | |
println(l.prefix + level + " " + msg) | |
} | |
return { | |
main, | |
NewLogger | |
} | |
})(); | |
main.main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment