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

setup of logger for slack java (logback / slf4j ) #1070

Closed
MING-LI opened this issue Oct 10, 2022 · 7 comments
Closed

setup of logger for slack java (logback / slf4j ) #1070

MING-LI opened this issue Oct 10, 2022 · 7 comments
Assignees
Labels
auto-triage-stale question M-T: User needs support to use the project

Comments

@MING-LI
Copy link

MING-LI commented Oct 10, 2022

By default following the example of slack web api, the dependencies like slf4j is necessary to include,
then it is needed to output and persist a log file in drive.

if there is any sample/documentation for slack logger setup for logging purpose both info or debug level (slf4j? or logback)
it could write a log file in a folder \log which the log folder is next to executable main program of .jar for sending msg to slack channel.

guess it needs an appender and config.xml (logback.xml) and add dependencies to pom file

got a main program and some threads will be generated by main function per message connection to be logged to a single logfile.

@MING-LI MING-LI changed the title setup of logger of slack (logback / slf4j ) setup of logger for slack java (logback / slf4j ) Oct 10, 2022
@hello-ashleyintech hello-ashleyintech self-assigned this Oct 10, 2022
@hello-ashleyintech hello-ashleyintech added question M-T: User needs support to use the project and removed untriaged labels Oct 10, 2022
@hello-ashleyintech
Copy link

Hi, @MING-LI! Thank so much for writing in! 🎉

We have a "Use Logger" section in our "Bolt Basics" guide within the Java SDK docs that touches on using either logback-classic or SLF4J with some code snippets. I hope this helps!

@MING-LI
Copy link
Author

MING-LI commented Oct 11, 2022

now logback dependencies setup in pom, but the log file doesnt show.

wonder what get wrong, I have try to use filewriter class of java which can write to the desired log destination to eliminate the without access rights factor.
<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.36</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.4.0</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.4.0</version> </dependency>

@WilliamBergamin
Copy link
Contributor

Hi @MING-LI, there is an example of logback configuration in the java starter template this is what the logback.xml file looks like.

I believe a fileAdapter may be required in order to log to a file.

Hopefully this helps you out 🗺️

@MING-LI
Copy link
Author

MING-LI commented Oct 14, 2022

Not sure what still missed out, still no progress
previously my post test should eliminate the write access by writing a test file out with test text inside.

Here is how my logback.xml looks:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="LOG_ROOT" value="C:/ABCtask/CDEmyslackjavaapp/logs" />
    <property name="LOG_FILE_NAME" value="slack_msg" />

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_ROOT}/${LOG_FILE_NAME}.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_ROOT}/${LOG_FILE_NAME}.%d{yyyy-MM-dd}.log</fileNamePattern>
            <!-- each archived file's size will be max 10MB -->
            <maxFileSize>10MB</maxFileSize>
            <!-- 60 days to keep -->
            <maxHistory>60</maxHistory>
            <!-- total size of all archive files, if total size > 100GB, it will delete old archived file -->
            <totalSizeCap>10GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="debug">
        <appender-ref ref="FILE" />
    </root>
</configuration>

Here comes the pom.xml snippet:

<dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.36</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.36</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.slack.api</groupId>
            <artifactId>slack-api-client</artifactId>
            <version>1.24.0</version>
        </dependency>		
</dependencies>
<build>
		 ...other details etc...
</build>

@seratch
Copy link
Member

seratch commented Oct 14, 2022

@MING-LI A few comments on your configuration:

  • When you use logback, you don't need to have slf4j-simple. You can (and perhaps should) remove it.
  • The latest version of logback is primarily compatible with slf4j-api 2.0. So, using the latest versions for your app may be safer. See also: Upgrade slf4j-api to 2.0 #1034

I haven't checked your log configuration on my end but when you are stuck with logging, I generally recommend starting with the examples in the library website (logback-classic in this case) and then gradually modifying it.

@github-actions
Copy link

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

@github-actions
Copy link

As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-triage-stale question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

4 participants