4

I have a software which logs various events into a database (SQLite). Currently the stored datas are :

  • Message
  • Date
  • Category
  • Criticality

The logs are written in the current software language. Which mean that the message :

User "admin" logged in

can become

L'utilisateur "admin" est connecté

if the software is in french.

That's perfect for the user, but sometimes users sends us their log file for analysis and it suddently become very complicated if it's a language that's nobody in the team can understand.

Which lead to my question , what strategy should we use to be able to display the logs in any language supported by our software independently of the original language ? knowing that :

  • Using a database is mandatory
  • The number of parameter in a logs message can go from 0 to a lot
  • The logs message should be understandable into the code
  • Exporting or displaying logs should be fast

Currently to write a logs message we are doing something like (C++)

std::string message = translate("User %s logged in"); // using Gettext
message = String::Format(message,userName);
LogsManager::Info(message);

Thanks

Edit The problematic is not to know if we should or not translate logs message but how to make them language independent. Meaning if user switch language during the use of the software ,messages should be displayed/exported in the current language and not in the previous one.

Doc Brown
  • 218,378
grunk
  • 183

1 Answers1

4

So you wrote you have

  • log messages in the database

  • as well as a log file which can be viewed and send per mail

That means there is a process from getting the messages out of the database into the file, for example, a button or menu feature Show Log (or at least, you could add such a feature).

The solution to your problem is to do the translation there, not earlier. Then the user can get a log file in his preferred language, and produce the same log file afterwards in a different language (for example, in english), before sending the log to you.

Of course, that will also mean you need to store

  • the english message templates in the database (instead of the final messages)
  • the parameters of each log message in the database (for this use case, one column with a comma separated aggregate of parameters will be sufficient).

So the logging table needs an additional column Parameters, and your logging code will look like this

  LogsManager::Info("User %s logged in", userName);

where the "Info" function has a variable parameter list, just like String::Format. The former calls to translate or String::Format should instead be moved to the "ShowLog" feature, and that feature then can get an additional option "output language".

We did something similar in a reporting tool where the input data was a complex XML file, containing a log section. The reports are produced in PDF, and the output language can be switched any time afterwards. All textual log messages are stored as templates + parameters, and get translated and combined as part of the PDF generation process - works like a charme.

Doc Brown
  • 218,378