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

can't print log to sentinel-record.log file with log4j JDK logging adapter #975

Closed
RojerAlone opened this issue Aug 8, 2019 · 22 comments
Closed
Labels
area/logging Issues or PRs related to logging of Sentinel kind/question Category issues related to questions or problems

Comments

@RojerAlone
Copy link

Describe what happened (or what feature you want)

I use nacos as dynamic rule center, and change rule in nacos console, i also receive the new rule, but can't see anything in sentinel-record.log file, is there some special config params?

There are 2 record log file, they are empty all:

-rw-r--r-- 1 work work    0 Aug  8 13:27 sentinel-record.log.2019-08-08.0
-rw-r--r-- 1 work work    0 Aug  8 13:27 sentinel-record.log.2019-08-08.0.lck

But the metrics.log is right.

And more, I run the code on my computer, and can see log, but deploy it to server, it will not.

Tell us your environment

Nacos client version is 1.0.0
Sentinel version is 1.6.2

@sentinel-bot sentinel-bot added the kind/bug Category issues or prs related to bug. label Aug 8, 2019
@RojerAlone RojerAlone changed the title can't pring log to sentinel-record.log file can't print log to sentinel-record.log file Aug 8, 2019
@sczyh30
Copy link
Member

sczyh30 commented Aug 8, 2019

Hi, are there any error messages in your stderr?

@sczyh30 sczyh30 added area/logging Issues or PRs related to logging of Sentinel kind/question Category issues related to questions or problems and removed kind/bug Category issues or prs related to bug. labels Aug 8, 2019
@RojerAlone
Copy link
Author

Hi, are there any error messages in your stderr?

No.

Besides, I set the log home by -Dcsp.sentinel.log.dir=/loghome, and only got below logs in my stdout:

INFO: log base dir is: /loghome
INFO: log name use pid is: false

@RojerAlone
Copy link
Author

Besides, I set the log home by -Dcsp.sentinel.log.dir=/loghome, and only got below logs in my stdout:

INFO: log base dir is: /loghome
INFO: log name use pid is: false

It's unrelated. I test it by setting log home on my computer and don't set it on server.

@linlinisme
Copy link
Collaborator

You mean on your computer you can see the log, and on server can not see? If so, it seems your application has not the write permission for the log dir.

@RojerAlone
Copy link
Author

@linlinisme I checked it, my application has permission, the metrics log is normal, and metrics log is in same directory with record log.

@sczyh30
Copy link
Member

sczyh30 commented Aug 9, 2019

Could you please try to add this JVM parameter: -Dcsp.sentinel.log.output.type=console and see whether the log appears in stdout

@RojerAlone
Copy link
Author

It seems there are some bad configuration in my code, record log is ok when I run my code in IDE, but it will not appear if I package my code and run it on server.
I'm looking for it.

@RojerAlone
Copy link
Author

Could you please try to add this JVM parameter: -Dcsp.sentinel.log.output.type=console and see whether the log appears in stdout

What means if the log doesn't appear in stdout? It does.

@sczyh30
Copy link
Member

sczyh30 commented Aug 13, 2019

It seems there are some bad configuration in my code, record log is ok when I run my code in IDE, but it will not appear if I package my code and run it on server.
I'm looking for it.

Any progress?

@RojerAlone
Copy link
Author

Maybe not. I use log4j in my service and I try to remove the log4j2.xml file or redirect all log to console, but can only see the other logs besides sentinel log.
I plan to debug it later.

@jasonjoo2010
Copy link
Collaborator

Maybe not. I use log4j in my service and I try to remove the log4j2.xml file or redirect all log to console, but can only see the other logs besides sentinel log.
I plan to debug it later.

If you just want to redirect all logs into console under log4j2 I have an easier way to achieve that.

reference in pom.xml:

      <dependency>
        <groupId>com.yoloho.enhanced</groupId>
        <artifactId>enhanced-common</artifactId>
        <version>1.0.2</version>
      </dependency>

And you can just remove the log4j2.xml in your project and add following code in initializing block:

// enable console, disable file logging
Logging.initLogging(true, false);

If you want do it more elegant you can refer to @InitDefaults in

https://github.com/yoloho/enhanced-spring

@cdfive
Copy link
Collaborator

cdfive commented Aug 23, 2019

Could you please try to add this JVM parameter: -Dcsp.sentinel.log.output.type=console and see whether the log appears in stdout

What means if the log doesn't appear in stdout? It does.

Sentinel provide a VM argument to choose output of biz log.

-Dcsp.sentinel.log.output.type default is file, print log to sentinel-record.log and command-center.log.

If set -Dcsp.sentinel.log.output.type=console, the log can be printed to stdout console.
You can have a try to test if the log is ok.

@sczyh30
Copy link
Member

sczyh30 commented Aug 29, 2019

Has this been resolved?

@RojerAlone
Copy link
Author

Sorry, I'm busy recently and I'll find time to do it.

@RojerAlone
Copy link
Author

@sczyh30
I debug it today, and found that the different of my computer with server is log framework. It will use java.util.logging.Logger when i run it on my computer, and it use log4j on server.

I add this to my log4j2.xml file and can see the log in Main appender log:

<Logger name="cspSentinelRecordLog" level="DEBUG" additivity="false">
    <AppenderRef ref="Main"/>
</Logger>

I'm not familiar with log framework, does log framework cause this?
And I think it will append to the root logger if not configure cspSentinelRecordLog logger, is it?

@sczyh30
Copy link
Member

sczyh30 commented Aug 31, 2019

You may check whether the content of Sentinel record log appeared in the log4j-configured log file.

@RojerAlone
Copy link
Author

There's not, only appeared when I add a logger named cspSentinelRecordLog.

@sczyh30
Copy link
Member

sczyh30 commented Nov 22, 2019

Has this been solved?

@RojerAlone
Copy link
Author

no, I think there's something wrong in the log framework properties, and had other people report the same question?

@RojerAlone
Copy link
Author

I debug it again, and find the root cause is that there's not any AppenderRef in the LoggerConfig object for sentinel log, then the logParent method would be called, but the additive field is false, so there are nothing in log file.
These are code and object info:

code from org.apache.logging.log4j.core.config.LoggerConfig class

LoggerConfig object

Is there somethint wrong in sentinel RecordLog class?

@RojerAlone
Copy link
Author

@sczyh30 I maybe have found the reason from the log4j official website:

The use of java.util.logging.Handler classes is NOT supported. Custom Handlers should instead use an appropriate Appender or code their own Appender plugin.

@sczyh30 sczyh30 changed the title can't print log to sentinel-record.log file can't print log to sentinel-record.log file with log4j JDK logging adapter Nov 25, 2019
@sczyh30
Copy link
Member

sczyh30 commented Jun 15, 2020

Since 1.7.2 you may leverage the Logger SPI.

@sczyh30 sczyh30 closed this as completed Jun 15, 2020
CST11021 pushed a commit to CST11021/Sentinel that referenced this issue Nov 3, 2021
[RIP-9] Polish Example_Orderly.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logging Issues or PRs related to logging of Sentinel kind/question Category issues related to questions or problems
Projects
None yet
Development

No branches or pull requests

6 participants