com.jcabi.log.Logger Java Examples
The following examples show how to use
com.jcabi.log.Logger.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Futures.java From jpeek with MIT License | 6 votes |
@Override public String asString() throws IOException { return Logger.format( // @checkstyle LineLength (1 line) "Artifacts=%d, processors=%d, threads=%d, freeMemory=%dM, maxMemory=%dM, totalMemory=%dM, ETA=%[ms]s:\n%s\n\nThreads: %s", this.queue.size(), Runtime.getRuntime().availableProcessors(), Thread.getAllStackTraces().keySet().size(), // @checkstyle MagicNumber (3 lines) Runtime.getRuntime().freeMemory() / (1024L << 10), Runtime.getRuntime().maxMemory() / (1024L << 10), Runtime.getRuntime().totalMemory() / (1024L << 10), new AvgOf( this.times.toArray(new Long[this.times.size()]) ).longValue() * (long) this.queue.size(), new Joined(", ", this.queue.keySet()).asString(), new Joined( ", ", new Mapped<>( Thread::getName, Thread.getAllStackTraces().keySet() ) ).asString() ); }
Example #2
Source File: Dynamo.java From jare with MIT License | 6 votes |
/** * Connect. * @return Region */ private static Region connect() { final String key = Manifests.read("Jare-DynamoKey"); final Credentials creds = new Credentials.Simple( key, Manifests.read("Jare-DynamoSecret") ); final Region region; if (key.startsWith("AAAAA")) { final int port = Integer.parseInt( System.getProperty("dynamo.port") ); region = new Region.Simple(new Credentials.Direct(creds, port)); Logger.warn(Dynamo.class, "test DynamoDB at port #%d", port); } else { region = new Region.Prefixed( new ReRegion(new Region.Simple(creds)), "jare-" ); } Logger.info(Dynamo.class, "DynamoDB connected as %s", key); return region; }
Example #3
Source File: CompileMojo.java From eo with MIT License | 6 votes |
/** * Compile one EO file. * @param file EO file */ private void compile(final Path file) { try { new Program( new InputOf(file), this.targetDirectory.toPath() ).compile(); } catch (final IOException ex) { throw new IllegalStateException( new UncheckedText( new FormattedText( "Can't compile %s into %s", file, this.targetDirectory ) ).asString(), ex ); } Logger.info(this, "%s compiled to %s", file, this.targetDirectory); }
Example #4
Source File: RetryWire.java From verano-http with MIT License | 5 votes |
@Override public final Dict send(final Dict request) { int attempt = 0; final String method = new Method.Of(request).asString(); final String uri = new RequestUri.Of(request).asString(); while (attempt < this.attempts) { try { final Dict response = this.origin.send(request); final int status = new Status.Of(response).intValue(); if (status < HttpURLConnection.HTTP_INTERNAL_ERROR) { return response; } Logger.warn( this, "%s %s returns %d status (attempt #%d)", method, uri, status, attempt + 1 ); //@checkstyle IllegalCatchCheck (1 lines) } catch (final Exception ex) { Logger.warn( this, "%s: %s", ex.getClass().getName(), ex.getLocalizedMessage() ); } ++attempt; } throw new IllegalStateException( String.format("Failed after %d attempts", attempt) ); }
Example #5
Source File: XslReport.java From jpeek with MIT License | 5 votes |
/** * Save report. * @param target Target dir * @throws IOException If fails */ @SuppressWarnings("PMD.GuardLogStatement") public void save(final Path target) throws IOException { final long start = System.currentTimeMillis(); final XML xml = new StrictXML( new ReportWithStatistics( this.post.transform(this.xml()) ), XslReport.SCHEMA ); new LengthOf( new TeeInput( xml.toString(), target.resolve( String.format("%s.xml", this.metric) ) ) ).intValue(); new LengthOf( new TeeInput( XslReport.STYLESHEET.transform(xml).toString(), target.resolve( String.format("%s.html", this.metric) ) ) ).intValue(); Logger.debug( this, "%s.xml generated in %[ms]s", this.metric, System.currentTimeMillis() - start ); }
Example #6
Source File: Skeleton.java From jpeek with MIT License | 5 votes |
/** * Calculate Xembly for all packages. * @return XML for all packages (one by one) */ @SuppressWarnings({ "PMD.AvoidInstantiatingObjectsInLoops", "PMD.GuardLogStatement" }) private Iterable<Map.Entry<String, Directives>> packages() { final long start = System.currentTimeMillis(); final Collection<Map.Entry<String, Directives>> all = new CopyOnWriteArrayList<>(); new Unchecked<>( new AndInThreads( new Mapped<>( clz -> () -> all.add(Skeleton.xembly(clz)), new Classes(this.base) ) ) ).value(); final Map<String, Directives> map = new HashMap<>(0); for (final Map.Entry<String, Directives> ent : all) { map.putIfAbsent(ent.getKey(), new Directives()); map.get(ent.getKey()).append(ent.getValue()); } Logger.debug( this, "%d classes parsed via ASM in %[ms]s", map.size(), System.currentTimeMillis() - start ); return map.entrySet(); }
Example #7
Source File: ReportsTest.java From jpeek with MIT License | 5 votes |
@BeforeEach public void weAreOnline() { try { new TextOf(new URL("http://www.jpeek.org/")).asString(); } catch (final IOException ex) { Logger.debug(this, "We are not online: %s", ex.getMessage()); Assumptions.assumeTrue(false); } }
Example #8
Source File: Logs.java From jare with MIT License | 5 votes |
@Override public void run() { try { final Iterator<String> ockets = this.bucket.list("").iterator(); if (ockets.hasNext()) { final String name = ockets.next(); final long bytes = this.process(name); this.bucket.remove(name); Logger.info(this, "ocket %s processed: %d bytes", name, bytes); } } catch (final IOException ex) { throw new IllegalStateException(ex); } }
Example #9
Source File: CompileMojo.java From eo with MIT License | 5 votes |
@Override public void execute() throws MojoFailureException { StaticLoggerBinder.getSingleton().setMavenLog(this.getLog()); if (this.targetDirectory.mkdirs()) { Logger.info(this, "Directory created: %s", this.targetDirectory); } try { Files.walk(this.sourceDirectory.toPath()) .filter(file -> !file.toFile().isDirectory()) .forEach(this::compile); } catch (final IOException ex) { throw new MojoFailureException( new UncheckedText( new FormattedText( "Can't list EO files in %s", this.sourceDirectory ) ).asString(), ex ); } this.project.addCompileSourceRoot( this.targetDirectory.getAbsolutePath() ); Logger.info( this, "Directory added to sources: %s", this.targetDirectory ); }
Example #10
Source File: AsyncReports.java From jpeek with MIT License | 4 votes |
@Override public Func<String, Response> apply(final String group, final String artifact) throws IOException { final Future<Func<String, Response>> future = new IoCheckedBiFunc<>( this.cache ).apply(group, artifact); final Func<String, Response> output; if (future.isCancelled()) { output = input -> new RsPage( new RqFake(), "error", () -> new IterableOf<>( new XeAppend("group", group), new XeAppend("artifact", artifact), new XeAppend("future", future.toString()) ) ); } else if (future.isDone()) { try { output = future.get(); } catch (final InterruptedException | ExecutionException ex) { throw new IllegalStateException(ex); } } else { final long msec = System.currentTimeMillis() - this.starts.computeIfAbsent( String.format("%s:%s", group, artifact), s -> System.currentTimeMillis() ); output = input -> new RsWithStatus( new RsPage( new RqFake(), "wait", () -> new IterableOf<>( new XeAppend("group", group), new XeAppend("artifact", artifact), new XeAppend("future", future.toString()), new XeAppend("msec", Long.toString(msec)), new XeAppend( "spent", Logger.format("%[ms]s", msec) ) ) ), HttpURLConnection.HTTP_NOT_FOUND ); } return output; }
Example #11
Source File: Futures.java From jpeek with MIT License | 4 votes |
@Override @SuppressWarnings("PMD.AvoidCatchingGenericException") public Future<Func<String, Response>> apply(final String group, final String artifact) { final String target = String.format("%s:%s", group, artifact); this.queue.put(target, System.currentTimeMillis()); // @checkstyle MagicNumber (1 line) if (this.times.size() > 1000) { this.times.clear(); } return this.service.submit( new VerboseCallable<>( () -> { Func<String, Response> front; try { Logger.info( this, "Started processing of %s:%s...", group, artifact ); front = this.origin.apply(group, artifact); this.times.add( System.currentTimeMillis() - this.queue.remove(target) ); Logger.info( this, "Finished processing of %s:%s", artifact, group ); // @checkstyle IllegalCatchCheck (4 lines) // @checkstyle AvoidCatchingGenericException (4 lines) } catch (final Exception ex) { Logger.error( this, "Failure in %s:%s: %s", group, artifact, ex.getMessage() ); front = input -> new RsPage( new RqFake(), "exception", () -> new IterableOf<>( new XeAppend("group", group), new XeAppend("artifact", artifact), new XeAppend( "stacktrace", new TextOf(new InputOf(ex)).asString() ) ) ); } return front; }, true, true ) ); }
Example #12
Source File: Results.java From jpeek with MIT License | 4 votes |
/** * Add result. * @param artifact The artifact, like "org.jpeek:jpeek" * @param dir Directory with files * @throws IOException If fails */ public void add(final String artifact, final Path dir) throws IOException { final XML index = new XMLDocument( dir.resolve("index.xml").toFile() ); final int elements = Integer.parseInt( index.xpath("max(/index/metric/elements/number(text()))").get(0) ); final Number diff = new DyNum(index.xpath("/index/@diff").get(0)); final long score = new DyNum( index.xpath("/index/@score").get(0) ).longValue(); final long rank = (long) ((double) score * (1.0d - diff.doubleValue())); // @checkstyle MagicNumber (1 line) if (elements < 100) { Logger.info( this, "%d elements NOT saved for %s by %s, rank=%d, score=%d, metrics=%d", elements, artifact, new Version().value(), rank, score, Integer.parseInt(index.xpath("count(/index/metric)").get(0)) ); } else { this.table.put( new Attributes() .with("good", "true") .with("artifact", artifact) .with("rank", rank) .with("score", score) .with("diff", diff.longValue()) .with( "defects", new DyNum( index.xpath("/index/@defects").get(0) ).longValue() ) .with("elements", elements) .with( "classes", Integer.parseInt( index.xpath( "/index/metric[1]/classes/text()" ).get(0) ) ) .with("version", new Version().value()) .with("added", System.currentTimeMillis()) .with( "ttl", System.currentTimeMillis() / TimeUnit.SECONDS.toMillis(1L) // @checkstyle MagicNumber (1 line) + TimeUnit.DAYS.toSeconds(100L) ) ); Logger.info( this, "%d elements saved for %s by %s, rank=%d, score=%d", elements, artifact, new Version().value(), rank, score ); } }
Example #13
Source File: Classes.java From jpeek with MIT License | 4 votes |
@Override @SuppressWarnings({ "PMD.PrematureDeclaration", "PMD.GuardLogStatement" }) public Iterator<CtClass> iterator() { final Collection<CtClass> classes; final long start = System.currentTimeMillis(); try { classes = new Filtered<>( // @checkstyle BooleanExpressionComplexityCheck (10 lines) ctClass -> !ctClass.isInterface() && !ctClass.isEnum() && !ctClass.isAnnotation() && !ctClass.getName().matches("^.+\\$[0-9]+$") && !ctClass.getName().matches("^.+\\$AjcClosure[0-9]+$"), new Mapped<>( path -> { try (InputStream stream = Files.newInputStream(path)) { return this.pool.makeClassIfNew(stream); } }, new Filtered<>( path -> Files.isRegularFile(path) && path.toString().endsWith(".class"), new CollectionOf<>(this.base.files()) ) ) ); } catch (final IOException ex) { throw new IllegalStateException(ex); } final Collection<CtClass> unique = new TreeSet<>( Comparator.comparing(CtClass::getName) ); unique.addAll(classes); Logger.debug( this, "%d classes found and parsed via Javassist in %[ms]s", unique.size(), System.currentTimeMillis() - start ); return unique.iterator(); }
Example #14
Source File: FkUsage.java From jare with MIT License | 4 votes |
@Override public void add(final Date date, final long bytes) { Logger.info(this, "usage, date=%s, bytes=%d", date, bytes); }