Skip to content

Instantly share code, notes, and snippets.

@tj tj/in.go
Last active Sep 23, 2017

Embed
What would you like to do?
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)
}
// 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
You can’t perform that action at this time.