Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to chain multiple shared lib's log, and identify log content using log header or instance id? #288

Open
blazewater-gmail opened this issue May 10, 2024 · 2 comments
Assignees
Labels

Comments

@blazewater-gmail
Copy link

blazewater-gmail commented May 10, 2024

hi,
I have multiple shared lib, and I want to chained their logs to main application;
in main app, I use multiple instance id and custom formater(log instance id string as header's part) to identify multiple modules in log text, but how can I identify log from diffent shared lib?
thx.

@SergiusTheBest SergiusTheBest self-assigned this May 10, 2024
@SergiusTheBest
Copy link
Owner

Hello! It's a good question.

One of the solutions I think about is to introduce a macro, for example PLOG_PREFIX, and set it to the library name. It will be automatically prepended to a log message. For example:

#define PLOG_PREFIX "[lib:fat32]"

...
PLOGD << "Hello!";

And the resulting string will be:

2024-05-10 19:36:51.840 DEBUG [30020] [main@37] [lib:fat32] Hello!

Will this work for you?

@blazewater-gmail
Copy link
Author

blazewater-gmail commented May 13, 2024

Hello! It's a good question.

One of the solutions I think about is to introduce a macro, for example PLOG_PREFIX, and set it to the library name. It will be automatically prepended to a log message. For example:

#define PLOG_PREFIX "[lib:fat32]"

...
PLOGD << "Hello!";

And the resulting string will be:

2024-05-10 19:36:51.840 DEBUG [30020] [main@37] [lib:fat32] Hello!

Will this work for you?

thanks for reply.
actually, now I define Log Facility in main app, for example:

 enum Facility {
    F1 = 1,
   F2 = 2,
   F3 = 3
};

and init these Facility Instances;

plog::init<Facility::F#>()...

then I define Log Facility for lib1 in Lib1.cpp, for example:

 enum {
    F1 = 1
};
init Facility in lib1.cpp

```c++
plog::init();
plog::init<F1>()...

chained lib1's log and main app's log, I can get corresponding log as Lib1.

but this is so weired.

so, I think your solution is better, but as logging analysis, suggest that add default prefix for main app.

Thanks again.

SergiusTheBest added a commit that referenced this issue May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants