Go: Create io.Writer inteface for logging to mongodb database

ساخت وبلاگ

Vote count: 0

Using go (golang):

Is there a way to create a logger that outputs to a database?

Or more precisely, can I implement some kind of io.Writer interface that I can pass as the first argument to log.New()?

EG: (dbLogger would receive the output of the log and write it to the database)

logger := log.New(dbLogger, "dbLog: ", log.Lshortfile) logger.Print("This message will be stored in the database")

I would assume that I should just create my own database logging function, but I was curious to see if there is already a way of doing this using the existing tools in the language.

For some context, I'm using mgo.v2 to handle my mongodb database, but I don't see any io.Writer interfaces there other than in GridFS, which I think solves a different problem.

I'm also still getting my head around the language, so I may have used some terms above incorrecly. Any corrections are very welcome.

asked 38 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 390 تاريخ : پنجشنبه 13 آبان 1395 ساعت: 14:21