开发者

SLF4J best practices

开发者 https://www.devze.com 2023-03-28 19:47 出处:网络
I\'m writing a library and I use sfl4j to handle logging. I think it\'s good idea as long as every body can provide it\'s own implementation and then, the log provided by my application will be handl

I'm writing a library and I use sfl4j to handle logging.

I think it's good idea as long as every body can provide it's own implementation and then, the log provided by my application will be handled correctly.

But I don't know if I have to provide an implementation as a transitive dependency or not.

Exemple:

If I only provide that:

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency开发者_如何学Go>
    </dependencies>

The user of my lib can choose the implementation, but if he just add my lib without reading configuration, it will not work

Otherwise, if I provide that:

    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.1</version>
        </dependency>
    </dependencies>

My lib will work correctly just when adding dependency to it, but If the user want to use an other slf4j, he will have to exclude mine.

What do you thing about that?


You never provide a log implementation. The client application has to do so. Otherwhise this would be a violation of separation of concerns. Don't do any assumptions about an unknown client.

0

精彩评论

暂无评论...
验证码 换一张
取 消