使用 logback,我正在尝试记录 IP 地址。我了解了日志记录,hostname但我无法记录服务器的本地 IP。有什么办法可以使用 logback 打印服务器的本地 IP 地址。
下面是我用于主机名打印的模式。
<appender name="APP_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${org.apache.nifi.bootstrap.config.log.dir}/nifi-app.log</file>
<define name="hostname" class="ch.qos.logback.core.property.CanonicalHostNamePropertyDefiner"/>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--
For daily rollover, use 'app_%d.log'.
For hourly rollover, use 'app_%d{yyyy-MM-dd_HH}.log'.
To GZIP rolled files, replace '.log' with '.log.gz'.
To ZIP rolled files, replace '.log' with '.log.zip'.
-->
<fileNamePattern>${org.apache.nifi.bootstrap.config.log.dir}/nifi-app_%d{yyyy-MM-dd_HH}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<!-- keep 30 log files worth of history -->
<maxHistory>30</maxHistory>
</rollingPolicy>
<immediateFlush>true</immediateFlush>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${hostname}%date %level [%thread] %logger{40} %msg%n</pattern>
</encoder>
</appender>
Run Code Online (Sandbox Code Playgroud) 我有一个对象,我想使用字符串索引访问该对象值,但是当我尝试在 TypeScript 中执行此操作时,出现错误。
// Declared Globally
const Orientation = {
value: () => 0,
'next_value': () => someFunction.anotherFunction.sqrt(),
};
// _textValue type declared
_textValue : string;
// Declared inside constructor
this._textValue = 'next_value';
// value used inside a function
_getValue(){
const newValue = Orientation[this._textValue]();
}
Run Code Online (Sandbox Code Playgroud)
在我使用的地方Orientation[this._textValue]();,我收到的错误如下:
元素隐式具有“any”类型,因为“any”类型的表达式不能用于索引类型“{ value: () => number;” '下一个值': () => 数字; }'.ts(7053)
关于如何解决这个问题有什么想法吗?