pax_global_header 0000666 0000000 0000000 00000000064 13760121360 0014511 g ustar 00root root 0000000 0000000 52 comment=8920c5da40f90c4e8b060e1c39357d04d007f152
jcabi-log-0.19.0/ 0000775 0000000 0000000 00000000000 13760121360 0013427 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/.0pdd.yml 0000664 0000000 0000000 00000000135 13760121360 0015056 0 ustar 00root root 0000000 0000000 errors:
- yegor256@gmail.com
# alerts:
# github:
# - yegor256
tags:
- pdd
- bug
jcabi-log-0.19.0/.gitattributes 0000664 0000000 0000000 00000000346 13760121360 0016325 0 ustar 00root root 0000000 0000000 # Check out all text files in UNIX format, with LF as end of line
# Don't change this file. If you have any ideas about it, please
# submit a separate issue about it and we'll discuss.
* text=auto eol=lf
*.java ident
*.xml ident
jcabi-log-0.19.0/.github/ 0000775 0000000 0000000 00000000000 13760121360 0014767 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/.github/ISSUE_TEMPLATE.md 0000664 0000000 0000000 00000001362 13760121360 0017476 0 ustar 00root root 0000000 0000000 Make sure the title of the issue explains the problem you are having. Also, the description of the issue must clearly explain what is broken, not what you want us to implement. Go through this checklist and make sure you answer "YES" to all points:
- You have all pre-requisites listed in README.md installed
- You are sure that you are not reporting a duplicate (search all issues)
- You say "is broken" or "doesn't work" in the title
- You tell us what you are trying to do
- You explain the results you are getting
- You suggest an alternative result you would like to see
This article will help you understand what we are looking for: http://www.yegor256.com/2014/11/24/principles-of-bug-tracking.html
Thank you for your contribution!
jcabi-log-0.19.0/.github/PULL_REQUEST_TEMPLATE.md 0000664 0000000 0000000 00000001227 13760121360 0020572 0 ustar 00root root 0000000 0000000 Many thanks for your contribution, we truly appreciate it. We will appreciate it even more, if you make sure that you can say "YES" to each point in this short checklist:
- You made a small amount of changes (less than 100 lines, less than 10 files)
- You made changes related to only one bug (create separate PRs for separate problems)
- You are ready to defend your changes (there will be a code review)
- You don't touch what you don't understand
- You ran the build locally and it passed
This article will help you understand what we are looking for: http://www.yegor256.com/2015/02/09/serious-code-reviewer.html
Thank you for your contribution!
jcabi-log-0.19.0/.gitignore 0000664 0000000 0000000 00000000074 13760121360 0015420 0 ustar 00root root 0000000 0000000 target/
.idea
jcabi-log.iml
/.project
.settings
/.classpath
jcabi-log-0.19.0/.pdd 0000664 0000000 0000000 00000000225 13760121360 0014176 0 ustar 00root root 0000000 0000000 --source=.
--verbose
--exclude target/**/*
--exclude src/main/resources/images/**/*
--rule min-words:20
--rule min-estimate:0
--rule max-estimate:90
jcabi-log-0.19.0/.rultor.yml 0000664 0000000 0000000 00000001413 13760121360 0015556 0 ustar 00root root 0000000 0000000 env:
MAVEN_OPTS: -XX:MaxPermSize=256m -Xmx1g
assets:
secring.gpg: yegor256/home#assets/secring.gpg
settings.xml: yegor256/home#assets/jcabi/settings.xml
pubring.gpg: yegor256/home#assets/pubring.gpg
install: |
sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
sudo gem install pdd
sudo gem install xcop
pdd --file=/dev/null
merge:
script: |-
mvn clean install -Pqulice --errors --settings ../settings.xml
deploy:
script: |-
mvn clean deploy -Pqulice --errors --settings ../settings.xml
release:
script: |-
mvn versions:set "-DnewVersion=${tag}"
git commit -am "${tag}"
mvn clean deploy -Pqulice -Psonatype -Pjcabi --errors --settings ../settings.xml
# mvn clean site-deploy -Pjcabi -Psite --errors --settings ../settings.xml
jcabi-log-0.19.0/.travis.yml 0000664 0000000 0000000 00000000723 13760121360 0015542 0 ustar 00root root 0000000 0000000 language: java
sudo: false
cache:
directories:
- $HOME/.m2
script:
- set -e
- mvn clean install -Pqulice --errors --batch-mode
- mvn clean
- pdd --source=$(pwd) --file=/dev/null
- est --dir=est --file=/dev/null
before_install:
- rvm install 2.6.0
- rvm use 2.6.0
install:
- gem install pdd -v 0.20.5
- gem install est -v 0.3.4
- gem install xcop -v 0.6
env:
global:
- MAVEN_OPTS="-Xmx256m"
- JAVA_OPTS="-Xmx256m"
jdk:
- openjdk8
jcabi-log-0.19.0/LICENSE.txt 0000664 0000000 0000000 00000002703 13760121360 0015254 0 ustar 00root root 0000000 0000000 Copyright (c) 2012-2020, jcabi.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met: 1) Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer. 2) Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution. 3) Neither the name of the jcabi.com nor
the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
jcabi-log-0.19.0/README.md 0000664 0000000 0000000 00000004514 13760121360 0014712 0 ustar 00root root 0000000 0000000
[](https://www.elegantobjects.org)
[](https://www.0crat.com/p/C3RUBL5H9)
[](http://www.rultor.com/p/jcabi/jcabi-log)
[](https://www.jetbrains.com/idea/)
[](https://travis-ci.org/jcabi/jcabi-log)
[](http://www.0pdd.com/p?name=jcabi/jcabi-log)
[](https://ci.appveyor.com/project/yegor256/jcabi-log/branch/master)
[](https://coveralls.io/github/jcabi/jcabi-log?branch=master)
[](https://i.jpeek.org/com.jcabi/jcabi-log/)
[](https://maven-badges.herokuapp.com/maven-central/com.jcabi/jcabi-log)
[](http://www.javadoc.io/doc/com.jcabi/jcabi-log)
[](https://hitsofcode.com/view/github/jcabi/jcabi-log)
More details are here: [log.jcabi.com](https://log.jcabi.com/index.html)
Read this blog post: [_Get Rid of Java Static Loggers_](https://www.yegor256.com/2014/05/23/avoid-java-static-logger.html)
`Logger` is a convenient static wrapper of [slf4j](http://www.slf4j.org/)
(don't forget to include one of [SLF4J Bindings](http://www.slf4j.org/manual.html#binding)
into the project):
```java
import com.jcabi.log.Logger;
class Foo {
void bar(int value) {
Logger.debug(this, "method #bar(%d) was called", value);
}
}
```
## How to contribute?
Fork the repository, make changes, submit a pull request.
We promise to review your changes same day and apply to
the `master` branch, if they look correct.
Please run Maven build before submitting a pull request:
```
$ mvn clean install -Pqulice
```
jcabi-log-0.19.0/appveyor.yml 0000664 0000000 0000000 00000002021 13760121360 0016012 0 ustar 00root root 0000000 0000000 version: '{build}'
skip_tags: true
clone_depth: 10
environment:
matrix:
- JAVA_HOME: C:\Program Files\Java\jdk1.7.0
#- JAVA_HOME: C:\Program Files\Java\jdk1.8.0
branches:
only:
- master
except:
- gh-pages
os: Windows Server 2012
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\maven" )) {
(new-object System.Net.WebClient).DownloadFile('http://www.us.apache.org/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.zip', 'C:\maven-bin.zip')
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
- cmd: SET PATH=C:\maven\apache-maven-3.2.5\bin;%JAVA_HOME%\bin;%PATH:C:\Ruby193\bin;=%
- cmd: SET MAVEN_OPTS=-XX:MaxPermSize=2g -Xmx4g
- cmd: SET JAVA_OPTS=-XX:MaxPermSize=2g -Xmx4g
- cmd: mvn --version
- cmd: java -version
build_script:
- mvn clean package -B -Dmaven.test.skip=true
test_script:
- mvn clean install --batch-mode -Pqulice
cache:
- C:\maven\
- C:\Users\appveyor\.m2
jcabi-log-0.19.0/pom.xml 0000664 0000000 0000000 00000011066 13760121360 0014750 0 ustar 00root root 0000000 0000000
4.0.0com.jcabijcabi1.26.0jcabi-log0.19.0jcabi-logbundleWrapper of SLF4J and a few supplementary logging classesgithubhttps://github.com/jcabi/jcabi-log/issuestravishttps://travis-ci.org/jcabi/jcabi-logscm:git:github.com:jcabi/jcabi-log.gitscm:git:github.com:jcabi/jcabi-log.githttps://github.com/jcabi/jcabi-loggithub-pageshttps://log.jcabi.com/org.projectlomboklomboklog4jlog4jcompiletrueorg.slf4jslf4j-api1.8.0-beta1org.junit.jupiterjunit-jupiter-params5.6.2testorg.apache.commonscommons-lang3testorg.apache.commonscommons-texttestmaven-surefire-pluginCp1251qulicecom.qulicequlice-maven-pluginfindbugs:.*duplicatefinder:.*
jcabi-log-0.19.0/src/ 0000775 0000000 0000000 00000000000 13760121360 0014216 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/ 0000775 0000000 0000000 00000000000 13760121360 0014632 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/ 0000775 0000000 0000000 00000000000 13760121360 0017371 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/invoker.properties 0000664 0000000 0000000 00000000033 13760121360 0023160 0 ustar 00root root 0000000 0000000 invoker.goals = clean test
jcabi-log-0.19.0/src/it/it-decoloring/pom.xml 0000664 0000000 0000000 00000004646 13760121360 0020720 0 ustar 00root root 0000000 0000000
4.0.0com.jcabijcabi1.26.0com.jcabijcabi-log-test1.0-SNAPSHOT@project.groupId@@project.artifactId@@project.version@org.apache.commonscommons-texttestlog4jlog4jtest
jcabi-log-0.19.0/src/it/it-decoloring/src/ 0000775 0000000 0000000 00000000000 13760121360 0020160 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/main/ 0000775 0000000 0000000 00000000000 13760121360 0021104 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/main/java/ 0000775 0000000 0000000 00000000000 13760121360 0022025 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/main/java/com/ 0000775 0000000 0000000 00000000000 13760121360 0022603 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/main/java/com/jcabi/ 0000775 0000000 0000000 00000000000 13760121360 0023653 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/main/java/com/jcabi/log/ 0000775 0000000 0000000 00000000000 13760121360 0024434 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/main/java/com/jcabi/log/MulticolorLayoutIntegration.java 0000664 0000000 0000000 00000003551 13760121360 0033036 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
/**
* Integration tests for MulticolorLayout. These have to
* be run with maven-invoker-plugin because they set the system property
* com.jcabi.log.coloring, which interferes with other tests (tests are run
* by multiple threads at once)
* @since 0.1
*/
public final class MulticolorLayoutIntegration {
}
jcabi-log-0.19.0/src/it/it-decoloring/src/main/java/com/jcabi/log/package-info.java 0000664 0000000 0000000 00000003117 13760121360 0027625 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Integration tests.
*/
package com.jcabi.log;
jcabi-log-0.19.0/src/it/it-decoloring/src/test/ 0000775 0000000 0000000 00000000000 13760121360 0021137 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/test/java/ 0000775 0000000 0000000 00000000000 13760121360 0022060 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/test/java/com/ 0000775 0000000 0000000 00000000000 13760121360 0022636 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/test/java/com/jcabi/ 0000775 0000000 0000000 00000000000 13760121360 0023706 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/test/java/com/jcabi/log/ 0000775 0000000 0000000 00000000000 13760121360 0024467 5 ustar 00root root 0000000 0000000 MulticolorLayoutIntegrationTest.java 0000664 0000000 0000000 00000017610 13760121360 0033653 0 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/it/it-decoloring/src/test/java/com/jcabi/log /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
/**
* Integration tests for MulticolorLayout. These have to
* be run with maven-invoker-plugin because they set the system property
* com.jcabi.log.coloring, which interferes with other tests (tests are run
* by multiple threads at once)
* @since 0.1
*/
public final class MulticolorLayoutIntegrationTest {
/**
* Conversation pattern for test case.
*/
private static final String CONV_PATTERN = "[%color{%p}] %color{%m}";
/**
* Property that dictates wheter the text should be coloured or not.
*/
private static final String COLORING_PROPERTY = "com.jcabi.log.coloring";
/**
* MulticolorLayout disables default color
* when -Dcom.jcabi.log.coloring=false.
* @throws Exception - if something goes wrong.
*/
@Test
public void disablesDefaultColor() throws Exception {
final MulticolorLayout layout = new MulticolorLayout();
layout.setConversionPattern(
MulticolorLayoutIntegrationTest.CONV_PATTERN
);
final LoggingEvent event = Mockito.mock(LoggingEvent.class);
Mockito.doReturn(Level.DEBUG).when(event).getLevel();
Mockito.doReturn("no color").when(event).getRenderedMessage();
MatcherAssert.assertThat(
StringEscapeUtils.escapeJava(layout.format(event)),
Matchers.equalTo(
"[\\u001B[2;37mDEBUG\\u001B[m] \\u001B[2;37mno color\\u001B[m"
)
);
System.getProperties().setProperty(
MulticolorLayoutIntegrationTest.COLORING_PROPERTY,
Boolean.FALSE.toString()
);
try {
MatcherAssert.assertThat(
StringEscapeUtils.escapeJava(layout.format(event)),
Matchers.equalTo(
"[DEBUG] no color"
)
);
} finally {
System.getProperties().setProperty(
MulticolorLayoutIntegrationTest.COLORING_PROPERTY,
Boolean.TRUE.toString()
);
}
}
/**
* MulticolorLayout disables the color that overwrites the default one.
* @throws Exception - if something goes wrong.
*/
@Test
public void disablesOverridenDefaultColor() throws Exception {
final MulticolorLayout layout = new MulticolorLayout();
layout.setConversionPattern("[%color{%p}] %m");
layout.setLevels("DEBUG:2;10");
final LoggingEvent event = Mockito.mock(LoggingEvent.class);
Mockito.doReturn(Level.DEBUG).when(event).getLevel();
Mockito.doReturn("no colour text").when(event).getRenderedMessage();
MatcherAssert.assertThat(
StringEscapeUtils.escapeJava(layout.format(event)),
Matchers.equalTo(
"[\\u001B[2;10mDEBUG\\u001B[m] no colour text"
)
);
System.getProperties().setProperty(
MulticolorLayoutIntegrationTest.COLORING_PROPERTY,
Boolean.FALSE.toString()
);
try {
MatcherAssert.assertThat(
StringEscapeUtils.escapeJava(layout.format(event)),
Matchers.equalTo(
"[DEBUG] no colour text"
)
);
} finally {
System.getProperties().setProperty(
MulticolorLayoutIntegrationTest.COLORING_PROPERTY,
Boolean.TRUE.toString()
);
}
}
/**
* MulticolorLayout disables constant color
* when -Dcom.jcabi.log.coloring=false.
* @throws Exception - if something goes wrong.
*/
@Test
public void disablesConstantColor() throws Exception {
final MulticolorLayout layout = new MulticolorLayout();
layout.setConversionPattern("[%color-blue{%p}] %color-blue{%m}");
final LoggingEvent event = Mockito.mock(LoggingEvent.class);
Mockito.doReturn(Level.DEBUG).when(event).getLevel();
Mockito.doReturn("no color text").when(event).getRenderedMessage();
MatcherAssert.assertThat(
StringEscapeUtils.escapeJava(layout.format(event)),
Matchers.equalTo(
"[\\u001B[34mDEBUG\\u001B[m] \\u001B[34mno color text\\u001B[m"
)
);
System.getProperties().setProperty(
MulticolorLayoutIntegrationTest.COLORING_PROPERTY,
Boolean.FALSE.toString()
);
try {
MatcherAssert.assertThat(
StringEscapeUtils.escapeJava(layout.format(event)),
Matchers.equalTo(
"[DEBUG] no color text"
)
);
} finally {
System.getProperties().setProperty(
MulticolorLayoutIntegrationTest.COLORING_PROPERTY,
Boolean.TRUE.toString()
);
}
}
/**
* MulticolorLayout disables the color that overwrites the constant one.
* @throws Exception - if something goes wrong.
*/
@Test
public void disablesOverridenConstantColor() throws Exception {
final MulticolorLayout layout = new MulticolorLayout();
layout.setConversionPattern("[%color-red{%p}] %color-red{%m}");
layout.setColors("red:12");
final LoggingEvent event = Mockito.mock(LoggingEvent.class);
Mockito.doReturn(Level.DEBUG).when(event).getLevel();
Mockito.doReturn("test").when(event).getRenderedMessage();
MatcherAssert.assertThat(
StringEscapeUtils.escapeJava(layout.format(event)),
Matchers.equalTo(
"[\\u001B[12mDEBUG\\u001B[m] \\u001B[12mtest\\u001B[m"
)
);
System.getProperties().setProperty(
MulticolorLayoutIntegrationTest.COLORING_PROPERTY,
Boolean.FALSE.toString()
);
try {
MatcherAssert.assertThat(
StringEscapeUtils.escapeJava(layout.format(event)),
Matchers.equalTo(
"[DEBUG] test"
)
);
} finally {
System.getProperties().setProperty(
MulticolorLayoutIntegrationTest.COLORING_PROPERTY,
Boolean.TRUE.toString()
);
}
}
}
jcabi-log-0.19.0/src/it/it-decoloring/src/test/java/com/jcabi/log/package-info.java 0000664 0000000 0000000 00000003117 13760121360 0027660 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* Integration tests.
*/
package com.jcabi.log;
jcabi-log-0.19.0/src/it/settings.xml 0000664 0000000 0000000 00000004471 13760121360 0017222 0 ustar 00root root 0000000 0000000
it-repotruelocal.central@localRepositoryUrl@truetruelocal.central@localRepositoryUrl@truetrue
jcabi-log-0.19.0/src/main/ 0000775 0000000 0000000 00000000000 13760121360 0015142 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/main/java/ 0000775 0000000 0000000 00000000000 13760121360 0016063 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/main/java/com/ 0000775 0000000 0000000 00000000000 13760121360 0016641 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/main/java/com/jcabi/ 0000775 0000000 0000000 00000000000 13760121360 0017711 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/main/java/com/jcabi/log/ 0000775 0000000 0000000 00000000000 13760121360 0020472 5 ustar 00root root 0000000 0000000 jcabi-log-0.19.0/src/main/java/com/jcabi/log/ColorfullyFormatted.java 0000664 0000000 0000000 00000004717 13760121360 0025346 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
/**
* Formats a log event using ANSI color codes.
* @since 0.18
*/
class ColorfullyFormatted implements Formatted {
/**
* The basic information to be formatted with colors.
*/
private final transient String basic;
/**
* Color used as the replacement.
*/
private final transient String color;
/**
* Constructor.
* @param bas Basic string to be formatted
* @param col Color to be used to paint the output
*/
ColorfullyFormatted(final String bas, final String col) {
this.basic = bas;
this.color = col;
}
@Override
public String format() {
return this.basic.replaceAll(
new ControlSequenceIndicatorFormatted("%s\\?m").format(),
String.format(
"%s%sm",
new ControlSequenceIndicatorFormatted("%s").format(),
this.color
)
);
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/Colors.java 0000664 0000000 0000000 00000006303 13760121360 0022600 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* Store human readable color data.
* @since 0.18
*/
public class Colors {
/**
* Colors with names.
*/
private final transient ConcurrentMap map;
/**
* Public ctor.
*/
public Colors() {
this.map = Colors.colorMap();
}
/**
* Add color to color map.
* @param key Key to add
* @param value Value to add
*/
public final void addColor(final String key, final String value) {
this.map.put(key, value);
}
/**
* Convert our text to ANSI color.
* @param meta Meta text
* @return ANSI color
*/
public final String ansi(final String meta) {
final String ansi;
if (meta == null) {
ansi = "?";
} else if (meta.matches("[a-z]+")) {
ansi = this.map.get(meta);
if (ansi == null) {
throw new IllegalArgumentException(
String.format("unknown color '%s'", meta)
);
}
} else {
ansi = meta;
}
return ansi;
}
/**
* Color map.
* @return Map of colors
*/
private static ConcurrentMap colorMap() {
final ConcurrentMap map =
new ConcurrentHashMap<>();
map.put("black", "30");
map.put("blue", "34");
map.put("cyan", "36");
map.put("green", "32");
map.put("magenta", "35");
map.put("red", "31");
map.put("yellow", "33");
map.put("white", "37");
return map;
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/ControlSequenceIndicatorFormatted.java 0000664 0000000 0000000 00000004171 13760121360 0030154 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
/**
* Replaces string format with a Control Sequence Indicator.
* @since 0.18
*/
public class ControlSequenceIndicatorFormatted implements Formatted {
/**
* Pattern to be used to find replacement points.
*/
private final transient String pattern;
/**
* Construtor.
* @param pat Pattern to be used to find replacement points
*/
public ControlSequenceIndicatorFormatted(final String pat) {
this.pattern = pat;
}
@Override
public final String format() {
return String.format(this.pattern, "\u001b\\[");
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/ConversionPattern.java 0000664 0000000 0000000 00000010611 13760121360 0025017 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Generates the conversion pattern.
* @since 0.18
*/
class ConversionPattern {
/**
* Regular expression for all matches.
*/
private static final Pattern METAS = Pattern.compile(
"%color(?:-([a-z]+|[0-9]{1,3};[0-9]{1,3};[0-9]{1,3}))?\\{"
);
/**
* Pattern to be validated.
*/
private final transient String pattern;
/**
* Colors to be used.
*/
private final transient Colors colors;
/**
* Constructor.
* @param pat Pattern to be used
* @param col Colors to be used
*/
ConversionPattern(final String pat, final Colors col) {
this.pattern = pat;
this.colors = col;
}
/**
* Generates the conversion pattern.
* @return Conversion pattern
*/
public String generate() {
String remaining = this.pattern;
final Matcher matcher = ConversionPattern.METAS.matcher(
remaining
);
final StringBuffer buf = new StringBuffer(0);
while (matcher.find()) {
final int argstart = matcher.end();
final int argend = findArgumentEnd(remaining, argstart);
if (argend < 0) {
break;
}
matcher.appendReplacement(buf, "");
buf.append(ConversionPattern.csi())
.append(this.colors.ansi(matcher.group(1)))
.append('m')
.append(remaining, argstart, argend)
.append(ConversionPattern.csi())
.append('m');
remaining = remaining.substring(argend + 1);
matcher.reset(remaining);
}
matcher.appendTail(buf);
return buf.toString();
}
/**
* Find the matching closing curly brace while keeping any nested curly
* brace pairs balanced.
* @param pattern Pattern to find the match in.
* @param start Index of first character after the opening curly brace
* @return Index of the closing curly brace, or -1 if not found
*/
private static int findArgumentEnd(final String pattern, final int start) {
int count = 1;
int index = start;
while (index < pattern.length()) {
final char character = pattern.charAt(index);
if (character == '}') {
--count;
if (count == 0) {
break;
}
} else if (character == '{') {
++count;
}
++index;
}
if (index == pattern.length()) {
index = -1;
}
return index;
}
/**
* Formats a string with a Control Sequence Information.
* @return Formatted string
*/
private static String csi() {
return new ControlSequenceIndicatorFormatted("%s").format();
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/DecorException.java 0000664 0000000 0000000 00000004606 13760121360 0024256 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Exception if some problem with decor.
*
* @since 0.1
*/
@ToString
@EqualsAndHashCode(callSuper = false)
final class DecorException extends Exception {
/**
* Serialization marker.
*/
private static final long serialVersionUID = 0x7526FA78EEDAC465L;
/**
* Public ctor.
* @param cause Cause of it
* @param format The message
* @param args Optional arguments
*/
DecorException(final Throwable cause, final String format,
final Object... args) {
super(String.format(format, args), cause);
}
/**
* Public ctor.
* @param format The message
* @param args Optional arguments
*/
DecorException(final String format, final Object... args) {
super(String.format(format, args));
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/DecorsManager.java 0000664 0000000 0000000 00000013500 13760121360 0024046 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Formattable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Manager of all decors.
*
* @since 0.1
*/
@ToString
@EqualsAndHashCode
final class DecorsManager {
/**
* Storage of all found decors.
* @checkstyle LineLength (2 lines)
*/
private static final ConcurrentMap> DECORS =
new ConcurrentHashMap<>(0);
static {
DecorsManager.DECORS.put("dom", DomDecor.class);
DecorsManager.DECORS.put("exception", ExceptionDecor.class);
DecorsManager.DECORS.put("list", ListDecor.class);
DecorsManager.DECORS.put("ms", MsDecor.class);
DecorsManager.DECORS.put("nano", NanoDecor.class);
DecorsManager.DECORS.put("object", ObjectDecor.class);
DecorsManager.DECORS.put("size", SizeDecor.class);
DecorsManager.DECORS.put("secret", SecretDecor.class);
DecorsManager.DECORS.put("text", TextDecor.class);
DecorsManager.DECORS.put("type", TypeDecor.class);
}
/**
* Private ctor.
*/
private DecorsManager() {
// empty
}
/**
* Get decor by key.
* @param key Key for the formatter to be used to fmt the arguments
* @param arg The arbument to supply
* @return The decor
* @throws DecorException If some problem
*/
@SuppressWarnings("PMD.ProhibitPublicStaticMethods")
public static Formattable decor(final String key, final Object arg)
throws DecorException {
final Class extends Formattable> type = DecorsManager.find(key);
final Formattable decor;
try {
decor = (Formattable) DecorsManager.ctor(type).newInstance(arg);
} catch (final InstantiationException ex) {
throw new DecorException(
ex,
"Can't instantiate %s(%s)",
type.getName(),
arg.getClass().getName()
);
} catch (final IllegalAccessException ex) {
throw new DecorException(
ex,
"Can't access %s(%s)",
type.getName(),
arg.getClass().getName()
);
} catch (final InvocationTargetException ex) {
throw new DecorException(
ex,
"Can't invoke %s(%s)",
type.getName(),
arg.getClass().getName()
);
}
return decor;
}
/**
* Find decor.
* @param key Key for the formatter to be used to fmt the arguments
* @return The type of decor found
* @throws DecorException If some problem
*/
@SuppressWarnings("unchecked")
private static Class extends Formattable> find(final String key)
throws DecorException {
final Class extends Formattable> type;
if (DecorsManager.DECORS.containsKey(key)) {
type = DecorsManager.DECORS.get(key);
} else {
try {
type = (Class) Class.forName(key);
} catch (final ClassNotFoundException ex) {
throw new DecorException(
ex,
"Decor '%s' not found and class can't be instantiated",
key
);
}
}
return type;
}
/**
* Get ctor of the type.
* @param type The type
* @return The ctor
* @throws DecorException If some problem
*/
private static Constructor> ctor(final Class extends Formattable> type)
throws DecorException {
final Constructor>[] ctors = type.getDeclaredConstructors();
if (ctors.length != 1) {
throw new DecorException(
"%s should have just one one-arg ctor, but there are %d",
type.getName(),
ctors.length
);
}
final Constructor> ctor = ctors[0];
if (ctor.getParameterTypes().length != 1) {
throw new DecorException(
"%s public ctor should have just once parameter",
type.getName()
);
}
return ctor;
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/DomDecor.java 0000664 0000000 0000000 00000007704 13760121360 0023041 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.io.StringWriter;
import java.util.Formattable;
import java.util.Formatter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.w3c.dom.Node;
/**
* Decorates XML Document.
*
* @since 0.1
*/
@ToString
@EqualsAndHashCode(of = "node")
final class DomDecor implements Formattable {
/**
* DOM transformer factory, DOM.
*/
private static final TransformerFactory FACTORY =
TransformerFactory.newInstance();
/**
* The document.
*/
private final transient Node node;
/**
* Public ctor.
* @param doc The document
* @throws DecorException If some problem with it
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
DomDecor(final Object doc) throws DecorException {
if (doc != null && !(doc instanceof Node)) {
throw new DecorException(
String.format(
"Instance of org.w3c.dom.Node required, while %s provided",
doc.getClass().getName()
)
);
}
this.node = (Node) doc;
}
// @checkstyle ParameterNumber (4 lines)
@Override
public void formatTo(final Formatter formatter, final int flags,
final int width, final int precision) {
final StringWriter writer = new StringWriter();
if (this.node == null) {
writer.write("NULL");
} else {
try {
final Transformer trans = DomDecor.FACTORY.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.STANDALONE, "no");
trans.transform(
new DOMSource(this.node),
new StreamResult(writer)
);
} catch (final TransformerConfigurationException ex) {
throw new IllegalStateException(ex);
} catch (final TransformerException ex) {
throw new IllegalStateException(ex);
}
}
formatter.format("%s", writer.toString());
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/DullyFormatted.java 0000664 0000000 0000000 00000004135 13760121360 0024277 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
/**
* Formats a log event without using ANSI color codes.
* @since 0.18
*/
class DullyFormatted implements Formatted {
/**
* String to be formatted.
*/
private final transient String basic;
/**
* Contructor.
* @param bas String to be formatted
*/
DullyFormatted(final String bas) {
this.basic = bas;
}
@Override
public String format() {
return this.basic.replaceAll(
new ControlSequenceIndicatorFormatted("%s([0-9]*|\\?)m").format(),
""
);
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/ExceptionDecor.java 0000664 0000000 0000000 00000005705 13760121360 0024257 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Formattable;
import java.util.FormattableFlags;
import java.util.Formatter;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Decorates an exception.
*
*
For example:
*
*
* try {
* // ...
* } catch (final IOException ex) {
* Logger.error("failed to open file: %[exception]s", ex);
* throw new IllegalArgumentException(ex);
* }
*
*
* @since 0.1
*/
@ToString
@EqualsAndHashCode(of = "throwable")
final class ExceptionDecor implements Formattable {
/**
* The exception.
*/
private final transient Throwable throwable;
/**
* Public ctor.
* @param thr The exception
*/
ExceptionDecor(final Throwable thr) {
this.throwable = thr;
}
// @checkstyle ParameterNumber (4 lines)
@Override
public void formatTo(final Formatter formatter, final int flags,
final int width, final int precision) {
final String text;
if (this.throwable == null) {
text = "NULL";
} else if ((flags & FormattableFlags.ALTERNATE) == 0) {
final StringWriter writer = new StringWriter();
this.throwable.printStackTrace(new PrintWriter(writer));
text = writer.toString();
} else {
text = this.throwable.getMessage();
}
formatter.format("%s", text);
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/Formatted.java 0000664 0000000 0000000 00000003423 13760121360 0023264 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
/**
* Contract for a class that know how to format something.
* @since 0.18
*/
interface Formatted {
/**
* Return something formatted.
* @return Formatted version of something
*/
String format();
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/ListDecor.java 0000664 0000000 0000000 00000006537 13760121360 0023240 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.Arrays;
import java.util.Collection;
import java.util.Formattable;
import java.util.Formatter;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Format list.
* @since 0.1
*/
@ToString
@EqualsAndHashCode(of = "list")
final class ListDecor implements Formattable {
/**
* The list.
*/
private final transient Collection> list;
/**
* Public ctor.
* @param obj The object to format
* @throws DecorException If some problem with it
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
ListDecor(final Object obj) throws DecorException {
if (obj == null || obj instanceof Collection) {
this.list = Collection.class.cast(obj);
} else if (obj instanceof Object[]) {
this.list = Arrays.asList((Object[]) obj);
} else {
throw new DecorException(
String.format(
"Collection or array required, while %s provided",
obj.getClass().getName()
)
);
}
}
// @checkstyle ParameterNumber (4 lines)
@Override
public void formatTo(final Formatter formatter, final int flags,
final int width, final int precision) {
final StringBuilder builder = new StringBuilder(0);
builder.append('[');
if (this.list == null) {
builder.append("NULL");
} else {
boolean first = true;
for (final Object item : this.list) {
if (!first) {
builder.append(", ");
}
builder.append(String.format("\"%s\"", item));
first = false;
}
}
builder.append(']');
formatter.format("%s", builder.toString());
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/Logger.java 0000664 0000000 0000000 00000042666 13760121360 0022572 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.logging.Level;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.slf4j.LoggerFactory;
/**
* Universal logger, and adapter between your app and SLF4J API.
*
*
Instead of relying
* on some logging engine you can use this class, which transforms all
* messages to SLF4J. This approach gives you a perfect decoupling of business
* logic and logging mechanism. All methods in the class are called
* statically, without the necessity to instantiate the class.
*
*
Use it like this in any class, and in any package:
*
*
package com.example.XXX;
* import com.jcabi.log.Logger;
* public class MyClass {
* public void foo(Integer num) {
* Logger.info(this, "foo(%d) just called", num);
* }
* }
*
*
Or statically (pay attention to {@code MyClass.class}):
*
*
public class MyClass {
* public static void foo(Integer num) {
* Logger.info(MyClass.class, "foo(%d) just called", num);
* }
* }
*
*
Exact binding between SLF4J and logging facility has to be
* specified in {@code pom.xml} of your project (or in classpath directly).
*
*
For performance reasons in most cases before sending a
* {@code TRACE} or {@code DEBUG} log message you may check whether this
* logging level is enabled in the project, e.g.:
*
*
There is only one reason to do so - if you want to save time spent on
* preparing of the arguments. By default, such a call is made inside every
* method of {@link Logger} class.
*
* @since 0.1
*/
@ToString
@EqualsAndHashCode
@SuppressWarnings(
{
"PMD.TooManyMethods", "PMD.GodClass", "PMD.ProhibitPublicStaticMethods"
}
)
public final class Logger {
/**
* Empty array of objects.
*/
private static final Object[] EMPTY = {};
/**
* UTF-8.
*/
private static final String UTF_8 = "UTF-8";
/**
* This is utility class.
*/
private Logger() {
// intentionally empty
}
/**
* Format one string.
* @param fmt The format
* @param args List of arbitrary arguments
* @return Formatted string
*/
public static String format(final String fmt, final Object... args) {
final String result;
if (args.length == 0) {
result = fmt;
} else {
final PreFormatter pre = new PreFormatter(fmt, args);
result = String.format(pre.getFormat(), pre.getArguments());
}
return result;
}
/**
* Protocol one message, with {@code TRACE} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged
* @since 0.7.11
*/
public static void trace(final Object source, final String msg) {
Logger.trace(source, msg, Logger.EMPTY);
}
/**
* Protocol one message, with {@code TRACE} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void trace(
final Object source,
final String msg, final Object... args
) {
if (Logger.isTraceEnabled(source)) {
Logger.traceForced(source, msg, args);
}
}
/**
* Protocol one message, with {@code TRACE} priority level
* without internal checking whether {@code TRACE} level is enabled.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void traceForced(
final Object source,
final String msg, final Object... args
) {
Logger.logger(source).trace(Logger.format(msg, args));
}
/**
* Protocol one message, with {@code DEBUG} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @since 0.7.11
*/
public static void debug(final Object source, final String msg) {
Logger.debug(source, msg, Logger.EMPTY);
}
/**
* Protocol one message, with {@code DEBUG} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void debug(
final Object source,
final String msg, final Object... args
) {
if (Logger.isDebugEnabled(source)) {
Logger.debugForced(source, msg, args);
}
}
/**
* Protocol one message, with {@code DEBUG} priority level
* without internal checking whether {@code DEBUG} level is enabled.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void debugForced(
final Object source,
final String msg, final Object... args
) {
Logger.logger(source).debug(Logger.format(msg, args));
}
/**
* Protocol one message, with {@code INFO} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged
* @since 0.7.11
*/
public static void info(final Object source, final String msg) {
Logger.info(source, msg, Logger.EMPTY);
}
/**
* Protocol one message, with {@code INFO} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void info(
final Object source,
final String msg, final Object... args
) {
if (Logger.isInfoEnabled(source)) {
Logger.infoForced(source, msg, args);
}
}
/**
* Protocol one message, with {@code INFO} priority level
* without internal checking whether {@code INFO} level is enabled.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void infoForced(
final Object source, final String msg,
final Object... args
) {
Logger.logger(source).info(Logger.format(msg, args));
}
/**
* Protocol one message, with {@code WARN} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged
* @since 0.7.11
*/
public static void warn(final Object source, final String msg) {
Logger.warn(source, msg, Logger.EMPTY);
}
/**
* Protocol one message, with {@code WARN} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void warn(
final Object source,
final String msg, final Object... args
) {
if (Logger.isWarnEnabled(source)) {
Logger.warnForced(source, msg, args);
}
}
/**
* Protocol one message, with {@code WARN} priority level
* without internal checking whether {@code WARN} level is enabled.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void warnForced(
final Object source,
final String msg, final Object... args
) {
Logger.logger(source).warn(Logger.format(msg, args));
}
/**
* Protocol one message, with {@code ERROR} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged
* @since 0.7.11
*/
public static void error(final Object source, final String msg) {
Logger.error(source, msg, Logger.EMPTY);
}
/**
* Protocol one message, with {@code ERROR} priority level.
* @param source The source of the logging operation
* @param msg The text message to be logged, with meta-tags
* @param args List of arguments
*/
public static void error(final Object source,
final String msg, final Object... args) {
Logger.logger(source).error(Logger.format(msg, args));
}
/**
* Validates whether {@code TRACE} priority level is enabled for
* this particular logger.
* @param source The source of the logging operation
* @return Is it enabled?
*/
public static boolean isTraceEnabled(final Object source) {
return Logger.logger(source).isTraceEnabled();
}
/**
* Validates whether {@code DEBUG} priority level is enabled for
* this particular logger.
* @param source The source of the logging operation
* @return Is it enabled?
*/
public static boolean isDebugEnabled(final Object source) {
return Logger.logger(source).isDebugEnabled();
}
/**
* Validates whether {@code INFO} priority level is enabled for
* this particular logger.
* @param source The source of the logging operation
* @return Is it enabled?
* @since 0.5
*/
public static boolean isInfoEnabled(final Object source) {
return Logger.logger(source).isInfoEnabled();
}
/**
* Validates whether {@code INFO} priority level is enabled for
* this particular logger.
* @param source The source of the logging operation
* @return Is it enabled?
* @since 0.5
*/
public static boolean isWarnEnabled(final Object source) {
return Logger.logger(source).isWarnEnabled();
}
/**
* Is the given logging level enabled?
* @param level The level of logging
* @param source The source of the logging operation
* @return Is it enabled?
* @since 0.13
*/
public static boolean isEnabled(final Level level, final Object source) {
boolean enabled = false;
if (level.equals(Level.SEVERE)) {
enabled = Logger.logger(source).isErrorEnabled();
} else if (level.equals(Level.WARNING)) {
enabled = Logger.logger(source).isWarnEnabled();
} else if (level.equals(Level.INFO) || level.equals(Level.CONFIG)) {
enabled = Logger.logger(source).isInfoEnabled();
} else if (level.equals(Level.FINE) || level.equals(Level.ALL)) {
enabled = Logger.logger(source).isDebugEnabled();
} else if (level.equals(Level.FINER) || level.equals(Level.FINEST)) {
enabled = Logger.logger(source).isTraceEnabled();
}
return enabled;
}
/**
* Log one line using the logging level specified.
* @param level The level of logging
* @param source The source of the logging operation
* @param msg The text message to be logged
* @param args Optional arguments for string formatting
* @since 0.8
* @checkstyle ParameterNumber (4 lines)
*/
public static void log(final Level level, final Object source,
final String msg, final Object... args) {
if (level.equals(Level.SEVERE)) {
Logger.error(source, msg, args);
} else if (level.equals(Level.WARNING)) {
Logger.warn(source, msg, args);
} else if (level.equals(Level.INFO) || level.equals(Level.CONFIG)) {
Logger.info(source, msg, args);
} else if (level.equals(Level.FINE) || level.equals(Level.ALL)) {
Logger.debug(source, msg, args);
} else if (level.equals(Level.FINER) || level.equals(Level.FINEST)) {
Logger.trace(source, msg, args);
}
}
/**
* Returns an {@link OutputStream}, which converts all incoming data
* into logging lines (separated by {@code \x0A} in UTF-8).
* @param level The level of logging
* @param source The source of the logging operation
* @return Output stream directly pointed to the logging facility
* @see some discussion
* @since 0.8
* @checkstyle MagicNumberCheck (20 lines)
*/
public static OutputStream stream(final Level level, final Object source) {
// @checkstyle AnonInnerLengthCheck (50 lines)
return new OutputStream() {
private final transient ByteArrayOutputStream buffer =
new ByteArrayOutputStream();
@Override
public void write(final int data) throws IOException {
if (data == '\n') {
Logger.log(
level, source,
this.buffer.toString(Logger.UTF_8)
);
this.buffer.reset();
} else if (data >= 0x20 && data <= 0x7f) {
this.buffer.write(data);
} else {
this.buffer.write(
String.format(
"\\x%02x", data & 0xff
).getBytes(Logger.UTF_8)
);
}
}
};
}
/**
* Log messages constructed from Suppliers.
* It is more efficient to use method referencing because the method
* won't be called unless the specified logging level is enabled.
*
* This saves you the effort of having to check if the level is enabled
* before calling the logging method.
* E.g.
*
* and the calculate() method won't be called unless the debug level is
* active.
*
* @return Object containing methods for logging with Supplier-constructed
* messages
*/
public static SupplierLogger withSupplier() {
return new SupplierLogger();
}
/**
* Set final static field in order to fix the %L log4j parameter.
* @param field Field
* @param value New value
* @throws NoSuchFieldException If some problem
* @throws IllegalAccessException If some problem
* @checkstyle ThrowsCountCheck (4 lines)
*/
private static void setFinalStatic(final Field field, final Object value)
throws NoSuchFieldException, IllegalAccessException {
field.setAccessible(true);
final Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, value);
}
/**
* Get the instance of the logger for this particular caller.
* @param source Source of the logging operation
* @return The instance of {@code Logger} class
*/
private static org.slf4j.Logger logger(final Object source) {
final org.slf4j.Logger logger;
if (source instanceof Class) {
logger = LoggerFactory.getLogger((Class>) source);
} else if (source instanceof String) {
logger = LoggerFactory.getLogger(String.class.cast(source));
} else {
logger = LoggerFactory.getLogger(source.getClass());
}
if ("org.slf4j.impl.Log4jLoggerAdapter"
.equals(logger.getClass().getName())) {
try {
final Field fqcn = logger.getClass()
.getDeclaredField("FQCN");
setFinalStatic(fqcn, Logger.class.getName());
} catch (final NoSuchFieldException ex) {
throw new IllegalStateException(ex);
} catch (final IllegalAccessException ex) {
throw new IllegalStateException(ex);
}
}
return logger;
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/MsDecor.java 0000664 0000000 0000000 00000011362 13760121360 0022674 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.Formattable;
import java.util.FormattableFlags;
import java.util.Formatter;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Decorate time interval in milliseconds.
*
*
For example:
*
*
* final long start = System.currentTimeMillis();
* // some operations
* Logger.debug("completed in %[ms]s", System.currentTimeMillis() - start);
*
*
* @since 0.1
*/
@ToString
@EqualsAndHashCode(of = "millis")
final class MsDecor implements Formattable {
/**
* The period to work with, in milliseconds.
*/
private final transient Double millis;
/**
* Public ctor.
* @param msec The interval in milliseconds
*/
@SuppressWarnings(
{
"PMD.NullAssignment",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"
}
)
MsDecor(final Long msec) {
if (msec == null) {
this.millis = null;
} else {
this.millis = Double.valueOf(msec);
}
}
// @checkstyle ParameterNumber (4 lines)
@Override
public void formatTo(final Formatter formatter, final int flags,
final int width, final int precision) {
if (this.millis == null) {
formatter.format("NULL");
} else {
final StringBuilder format = new StringBuilder(0);
format.append('%');
if ((flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags
.LEFT_JUSTIFY) {
format.append('-');
}
if (width > 0) {
format.append(Integer.toString(width));
}
if ((flags & FormattableFlags.UPPERCASE) == FormattableFlags
.UPPERCASE) {
format.append('S');
} else {
format.append('s');
}
formatter.format(format.toString(), this.toText(precision));
}
}
/**
* Create text.
* @param precision The precision
* @return The text
* @checkstyle MagicNumber (50 lines)
*/
private String toText(final int precision) {
final double number;
final String title;
if (this.millis < 1000.0) {
number = this.millis;
title = "ms";
} else if (this.millis < (double) (1000L * 60L)) {
number = this.millis / 1000.0;
title = "s";
} else if (this.millis < (double) (1000L * 60L * 60L)) {
number = this.millis / (double) (1000L * 60L);
title = "min";
} else if (this.millis < (double) (1000L * 60L * 60L * 24L)) {
number = this.millis / (double) (1000L * 60L * 60L);
title = "hr";
} else if (this.millis < (double) (1000L * 60L * 60L * 24L * 30L)) {
number = this.millis / (double) (1000L * 60L * 60L * 24L);
title = "days";
} else {
number = this.millis / (double) (1000L * 60L * 60L * 24L * 30L);
title = "mon";
}
final String format;
if (precision >= 0) {
format = String.format("%%.%df%%s", precision);
} else {
format = "%.0f%s";
}
return String.format(format, number, title);
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/MulticolorLayout.java 0000664 0000000 0000000 00000017157 13760121360 0024677 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.log4j.EnhancedPatternLayout;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
/**
* Multi-color layout for LOG4J.
*
*
The part of the message wrapped with {@code %color{...}}
* will change its color according to the logging level of the event. Without
* this highlighting the behavior of the layout is identical to
* {@link EnhancedPatternLayout}. You can use {@code %color-red{...}} if you
* want to use specifically red color for the wrapped piece of text. Supported
* colors are: {@code red}, {@code blue}, {@code yellow}, {@code cyan},
* {@code black}, and {@code white}.
*
*
Besides that you can specify any ANSI color you like with
* {@code %color-;;{...}}, where
* {@code } is a binary mask of attributes,
* {@code } is a background color, and
* {@code } is a foreground color. Read more about
* ANSI escape code.
*
*
This class or its parents are not serializable.
*
*
* @since 0.1.10
* @see ANSI escape code
* @see PatternLayout from LOG4J
* @see How to use with Maven
*/
@ToString
@EqualsAndHashCode(callSuper = false)
@SuppressWarnings("PMD.NonStaticInitializer")
public final class MulticolorLayout extends EnhancedPatternLayout {
/**
* Name of the property that is used to disable log coloring.
*/
private static final String COLORING_PROPERY = "com.jcabi.log.coloring";
/**
* Colors of levels.
*/
private final transient ConcurrentMap levels =
MulticolorLayout.levelMap();
/**
* Store original conversation pattern to be able
* to recalculate it, if new colors are provided.
*/
private transient String base;
/**
* Color human readable data.
*/
private final transient Colors colors = new Colors();
@Override
public void setConversionPattern(final String pattern) {
this.base = pattern;
super.setConversionPattern(
new ConversionPattern(this.base, this.colors).generate()
);
}
/**
* Allow to overwrite or specify new ANSI color names
* in a javascript map like format.
*
* @param cols JavaScript like map of color names
* @since 0.9
*/
@SuppressWarnings("PMD.UseConcurrentHashMap")
public void setColors(final String cols) {
final Map parsed = new ParseableInformation(
cols
).information();
for (final Entry entry : parsed.entrySet()) {
this.colors.addColor(entry.getKey(), entry.getValue());
}
if (this.base != null) {
this.setConversionPattern(this.base);
}
}
/**
* Allow to overwrite the ANSI color values for the log levels
* in a javascript map like format.
* @param lev JavaScript like map of levels
* @since 0.9
*/
@SuppressWarnings("PMD.UseConcurrentHashMap")
public void setLevels(final String lev) {
final Map parsed = new ParseableLevelInformation(
lev
).information();
for (final Entry entry : parsed.entrySet()) {
this.levels.put(entry.getKey(), entry.getValue());
}
}
@Override
public String format(final LoggingEvent event) {
final Formatted formatted;
if (MulticolorLayout.isColoringEnabled()) {
formatted = this.colorfulFormatting(event);
} else {
formatted = this.dullFormatting(event);
}
return formatted.format();
}
/**
* Generate a dull {@code Formatted}.
* @param event Event to be formatted
* @return A {@link Formatted} to format the event
* @checkstyle NonStaticMethodCheck (10 lines)
*/
private Formatted dullFormatting(final LoggingEvent event) {
return new DullyFormatted(super.format(event));
}
/**
* Generate a colorful {@code Formatted}.
* @param event Event to be formatted
* @return Text of a log event, probably colored with ANSI color codes
*/
private Formatted colorfulFormatting(final LoggingEvent event) {
return new ColorfullyFormatted(
super.format(event),
this.levels.get(event.getLevel().toString())
);
}
/**
* Level map.
* @return Map of levels
*/
private static ConcurrentMap levelMap() {
final ConcurrentMap map = new ConcurrentHashMap<>(0);
map.put(Level.TRACE.toString(), "2;33");
map.put(Level.DEBUG.toString(), "2;37");
map.put(Level.INFO.toString(), "0;37");
map.put(Level.WARN.toString(), "0;33");
map.put(Level.ERROR.toString(), "0;31");
map.put(Level.FATAL.toString(), "0;35");
return map;
}
/**
* Should the logged text be colored or not.
* @return True if the coloring is enabled, or false otherwise.
*/
private static boolean isColoringEnabled() {
return !"false".equals(
System.getProperty(MulticolorLayout.COLORING_PROPERY)
);
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/NanoDecor.java 0000664 0000000 0000000 00000010733 13760121360 0023211 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.Formattable;
import java.util.FormattableFlags;
import java.util.Formatter;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Decorate time interval in nanoseconds.
*
*
For example:
*
*
* final long start = System.nanoTime();
* // some operations
* Logger.debug("completed in %[nano]s", System.nanoTime() - start);
*
*
* @since 0.1
*/
@ToString
@EqualsAndHashCode(of = "nano")
final class NanoDecor implements Formattable {
/**
* The period to work with, in nanoseconds.
*/
private final transient Double nano;
/**
* Public ctor.
* @param nan The interval in nanoseconds
*/
@SuppressWarnings(
{
"PMD.NullAssignment",
"PMD.ConstructorOnlyInitializesOrCallOtherConstructors"
}
)
NanoDecor(final Long nan) {
if (nan == null) {
this.nano = null;
} else {
this.nano = Double.valueOf(nan);
}
}
// @checkstyle ParameterNumber (4 lines)
@Override
public void formatTo(final Formatter formatter, final int flags,
final int width, final int precision) {
if (this.nano == null) {
formatter.format("NULL");
} else {
final StringBuilder format = new StringBuilder(0);
format.append('%');
if ((flags & FormattableFlags.LEFT_JUSTIFY) == FormattableFlags
.LEFT_JUSTIFY) {
format.append('-');
}
if (width > 0) {
format.append(Integer.toString(width));
}
if ((flags & FormattableFlags.UPPERCASE) == FormattableFlags
.UPPERCASE) {
format.append('S');
} else {
format.append('s');
}
formatter.format(format.toString(), this.toText(precision));
}
}
/**
* Create text.
* @param precision The precision
* @return The text
*/
private String toText(final int precision) {
final double number;
final String title;
// @checkstyle MagicNumber (15 lines)
if (this.nano < 1000L) {
number = this.nano;
title = "ns";
} else if (this.nano < 1000L * 1000) {
number = this.nano / 1000L;
title = "µs";
} else if (this.nano < 1000L * 1000 * 1000) {
number = this.nano / (1000L * 1000);
title = "ms";
} else if (this.nano < 1000L * 1000 * 1000 * 60) {
number = this.nano / (1000L * 1000 * 1000);
title = "s";
} else {
number = this.nano / (1000L * 1000 * 1000 * 60);
title = "min";
}
final String format;
if (precision >= 0) {
format = String.format("%%.%df%%s", precision);
} else {
format = "%.0f%s";
}
return String.format(format, number, title);
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/ObjectDecor.java 0000664 0000000 0000000 00000012565 13760121360 0023531 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.Formattable;
import java.util.Formatter;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Format internal structure of an object.
* @since 0.1
*/
@ToString
@EqualsAndHashCode(of = "object")
final class ObjectDecor implements Formattable {
/**
* The object to work with.
*/
private final transient Object object;
/**
* Public ctor.
* @param obj The object to format
*/
ObjectDecor(final Object obj) {
this.object = obj;
}
// @checkstyle ParameterNumber (4 lines)
@Override
public void formatTo(final Formatter formatter, final int flags,
final int width, final int precision) {
if (this.object == null) {
formatter.format("NULL");
} else if (this.object.getClass().isArray()) {
formatter.format(
AccessController.doPrivileged(
new ArrayFormatAction((Object[]) this.object)
)
);
} else {
final String output =
AccessController.doPrivileged(
new ObjectDecor.ObjectContentsFormatAction(this.object)
);
formatter.format(output);
}
}
/**
* {@link PrivilegedAction} for obtaining array contents.
*
* @since 0.1
*/
private static final class ArrayFormatAction
implements PrivilegedAction {
/**
* Array to format.
*/
private final transient Object[] array;
/**
* Constructor.
* @param arr Array to format
*/
ArrayFormatAction(final Object... arr) {
this.array = Arrays.copyOf(arr, arr.length);
}
@Override
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public String run() {
final StringBuilder builder = new StringBuilder("[");
final Formatter formatter = new Formatter(builder);
for (final Object obj : this.array) {
new ObjectDecor(obj).formatTo(formatter, 0, 0, 0);
// @checkstyle MultipleStringLiteralsCheck (1 line)
builder.append(", ");
}
builder.replace(builder.length() - 2, builder.length(), "]");
return builder.toString();
}
}
/**
* {@link PrivilegedAction} for obtaining object contents.
*
* @since 0.1
*/
private static final class ObjectContentsFormatAction
implements PrivilegedAction {
/**
* Object to format.
*/
private final transient Object object;
/**
* Constructor.
* @param obj Object to format
*/
ObjectContentsFormatAction(final Object obj) {
this.object = obj;
}
@Override
public String run() {
final StringBuilder builder = new StringBuilder("{");
for (final Field field
: this.object.getClass().getDeclaredFields()) {
field.setAccessible(true);
try {
builder.append(
String.format(
"%s: \"%s\"",
field.getName(),
field.get(this.object)
)
);
} catch (final IllegalAccessException ex) {
throw new IllegalStateException(ex);
}
// @checkstyle MultipleStringLiteralsCheck (1 line)
builder.append(", ");
}
builder.replace(builder.length() - 2, builder.length(), "}");
return builder.toString();
}
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/ParseableInformation.java 0000664 0000000 0000000 00000006213 13760121360 0025443 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.HashMap;
import java.util.Map;
/**
* Converts items inside a string like K1:V1,K2:V2 - where K is for key and V
* is for value - to a {@code Map} of string key and string value.
* @since 0.18
*/
class ParseableInformation {
/**
* Information content to be parsed.
*/
private final transient String content;
/**
* Construtor.
* @param cont Content to be parsed
*/
ParseableInformation(final String cont) {
super();
this.content = cont;
}
/**
* Parse the information.
* @return A {@link Map} with a key,value pair os strings
*/
@SuppressWarnings("PMD.UseConcurrentHashMap")
public final Map information() {
final Map parsed = new HashMap<>(0);
try {
for (final String item : this.items()) {
final String[] values = item.split(":");
parsed.put(values[0], values[1]);
}
} catch (final ArrayIndexOutOfBoundsException ex) {
throw new IllegalStateException(
String.format(new StringBuilder()
.append("Information is not using the pattern ")
.append("KEY1:VALUE,KEY2:VALUE %s")
.toString(),
this.content
), ex
);
}
return parsed;
}
/**
* Split the information using {@link ParseableInformation#SPLIT_ITEMS}
* pattern.
* @return An array of items
*/
private String[] items() {
return this.content.split(",");
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/ParseableLevelInformation.java 0000664 0000000 0000000 00000005710 13760121360 0026434 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.log4j.Level;
/**
* Parse information like {@code ParseInformation} does, but increments with
* some extra checks for {@code Level}s.
* @since 0.18
*/
class ParseableLevelInformation {
/**
* Information content to be parsed.
*/
private final transient String content;
/**
* Construtor.
* @param cont Content to be parsed
*/
ParseableLevelInformation(final String cont) {
this.content = cont;
}
/**
* Parse the level information.
* @return A {@link Map} with key,value pair of strings
*/
@SuppressWarnings("PMD.UseConcurrentHashMap")
public final Map information() {
final Map parsed = new ParseableInformation(
this.content
).information();
final Map converted = new HashMap<>(0);
for (final Entry entry : parsed.entrySet()) {
final String level = entry.getKey().toUpperCase(Locale.ENGLISH);
if (Level.toLevel(level, null) == null) {
throw new IllegalStateException(
String.format(Locale.ENGLISH, "Unknown level '%s'", level)
);
}
converted.put(level, entry.getValue());
}
return converted;
}
}
jcabi-log-0.19.0/src/main/java/com/jcabi/log/PreFormatter.java 0000664 0000000 0000000 00000013143 13760121360 0023751 0 ustar 00root root 0000000 0000000 /*
* Copyright (c) 2012-2020, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jcabi.log;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* Processor of formatting string and arguments, before sending it to
* {@link String#format(String,Object[])}.
*
* @since 0.1
*/
@ToString
@EqualsAndHashCode(of = { "format", "arguments" })
final class PreFormatter {
/**
* Pattern used for matching format string arguments.
*/
private static final Pattern PATTERN = Pattern.compile(
// @checkstyle LineLength (1 line)
"%(\\d+\\$)?(\\[([A-Za-z\\-\\.0-9]+)\\])?[\\+\\-]?(?:\\d*(?:\\.\\d+)?)?[a-zA-Z%]"
);
/**
* List of no argument specifier.
*/
private static final List NO_ARG_SPECIFIERS =
Arrays.asList("%n", "%%");
/**
* The formatting string.
*/
private transient String format;
/**
* List of arguments.
*/
private transient List