V
V
v- death2015-11-05 20:37:45
MySQL
v- death, 2015-11-05 20:37:45

What do you think about my logging implementation?

Hello. I made a flexible logging system. I can add new types of logs to the config and delete them

"Types"     : [
    "Debug",
    "Info",
    "Warn",
    "Error",
    "Fatal"
  ]

I can also easily add a type that needs to be notified by email
"EmailSend" : [
    "Error",
    "Fatal"
]

Now about the architecture
There is a library that I use in my code. Its use is elementary
logs.New("Debug","test")
It checks the data and writes it in the format
('time log','type log','message log'),('time log','type log','message log'),('time log','type log','message log')

in radish. A daemon hangs in the background, which every n-seconds deletes data from the radish and places them in a bunch in the database (currently in mysql). As a result, I can drive at least 800k logs into the database without a heavy load on it. What are some tips to improve my craft? is it worth writing an article about it on Habré and uploading it to github? Thanks to all.
UPD
Data in radish pastebin.com/PUvLpRgL
Config pastebin.com/GeZxCnGU
From the data in radish I delete the last coma and shove them into sql query
DB.Exec("INSERT INTO " + MysqlTable + " (type,time,messages) VALUES" + strings.TrimRight(data, ","))

And I update the data in the radish on a space. And so in an eternal loop (it slows down with the help of time.Sleep for the number of seconds specified in the config)
I just added 1,000,000 records to the muscle in 25ms on a weak vps (frequency 1.6; 1 core, 2 GB of RAM) in a boxed configuration.
Article + all code on Habré

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2015-11-05
@vGrabko99

1. Replace strings with constants, preferably numeric. It will be less likely to make a mistake, because the constants are checked during compilation, plus it will work faster (in the case of numeric constants).
2. It's worth trying RabbitMq to manage the db write queue instead of cycling. Or you can try specialized databases that are created specifically for storing logs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question