当前位置: 首页>>代码示例>>Java>>正文


Java Logger.format方法代码示例

本文整理汇总了Java中com.jcabi.log.Logger.format方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.format方法的具体用法?Java Logger.format怎么用?Java Logger.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jcabi.log.Logger的用法示例。


在下文中一共展示了Logger.format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: asString

import com.jcabi.log.Logger; //导入方法依赖的package包/类
@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 JoinedText(", ", this.queue.keySet()).asString(),
        new JoinedText(
            ", ",
            new Mapped<>(
                Thread::getName,
                Thread.getAllStackTraces().keySet()
            )
        ).asString()
    );
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:26,代码来源:Futures.java

示例2: append

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Append new element.
 * @param element The element to append
 * @return This object
 */
public final T append(@NotNull final Object element) {
    if (!element.getClass().isAnnotationPresent(XmlRootElement.class)) {
        throw new IllegalArgumentException(
            Logger.format(
                "class %[type]s doesn't have @XmlRootElement annotation",
                element
            )
        );
    }
    this.elements.add(element);
    XslResolver.class.cast(
        this.home().providers().getContextResolver(
            Marshaller.class,
            MediaType.APPLICATION_XML_TYPE
        )
    ).add(element.getClass());
    return (T) this;
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:24,代码来源:BasePage.java

示例3: transform

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Transform XML into HTML.
 * @param xml XML page to be transformed.
 * @return Resulting HTML page.
 * @throws ServletException If some problem inside
 * @checkstyle RedundantThrows (2 lines)
 */
private String transform(final String xml) throws ServletException {
    final StringWriter writer = new StringWriter();
    try {
        this.transformer(this.stylesheet(xml)).transform(
            this.source(xml),
            new StreamResult(writer)
        );
    } catch (final TransformerException ex) {
        throw new ServletException(
            Logger.format(
                "Failed to transform XML to XHTML: '%s'",
                xml
            ),
            ex
        );
    }
    return writer.toString();
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:26,代码来源:XsltFilter.java

示例4: transformer

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Make a transformer from this stylesheet.
 * @param stylesheet The stylesheet
 * @return Transformer
 * @throws ServletException If fails
 * @checkstyle RedundantThrows (3 lines)
 */
private Transformer transformer(final Source stylesheet)
    throws ServletException {
    final Transformer tran;
    try {
        tran = this.tfactory.newTransformer(stylesheet);
    } catch (final TransformerConfigurationException ex) {
        throw new ServletException(
            Logger.format(
                "Failed to create an XSL transformer for '%s'",
                stylesheet.getSystemId()
            ),
            ex
        );
    }
    if (tran == null) {
        throw new ServletException(
            Logger.format(
                "%[type]s failed to create new XSL transformer for '%s'",
                this.tfactory,
                stylesheet.getSystemId()
            )
        );
    }
    return tran;
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:33,代码来源:XsltFilter.java

示例5: local

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Load stream from local address.
 * @param path The path to resource to load from
 * @param base Base of request
 * @return The stream opened or NULL if nothing found
 * @throws TransformerException If not found
 */
private Source local(final String path, final String base)
    throws TransformerException {
    if (path.charAt(0) != '/' && path.charAt(0) != '.'
        && path.charAt(0) != '\\') {
        throw new TransformerException(
            String.format("'%s' is not a local path", path)
        );
    }
    final String abs = ContextResourceResolver.compose(path, base);
    final InputStream stream = this.context.getResourceAsStream(abs);
    if (stream == null) {
        throw new TransformerException(
            Logger.format(
                // @checkstyle LineLength (1 line)
                "local resource '%s' not found by %[type]s, abs='%s', realPath='%s'",
                path, this.context, abs, this.context.getRealPath(abs)
            )
        );
    }
    final Source source = ContextResourceResolver.source(stream);
    source.setSystemId(abs);
    return source;
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:31,代码来源:ContextResourceResolver.java

示例6: http

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Fetch stream from HTTP connection.
 * @param conn The connection to fetch from
 * @return The stream opened
 * @throws IOException If some problem happens
 */
private static InputStream http(final HttpURLConnection conn)
    throws IOException {
    InputStream stream;
    try {
        conn.connect();
        final int code = conn.getResponseCode();
        if (code != HttpURLConnection.HTTP_OK) {
            throw new IOException(
                Logger.format(
                    "Invalid HTTP response code %d at '%s'",
                    code, conn.getURL()
                )
            );
        }
        stream = IOUtils.toInputStream(
            IOUtils.toString(conn.getInputStream(), CharEncoding.UTF_8),
            CharEncoding.UTF_8
        );
    } finally {
        conn.disconnect();
    }
    return stream;
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:30,代码来源:ContextResourceResolver.java

示例7: read

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Read one attribute available in one of {@code MANIFEST.MF} files.
 *
 * <p>If such a attribute doesn't exist {@link IllegalArgumentException}
 * will be thrown. If you're not sure whether the attribute is present or
 * not use {@link #exists(String)} beforehand.
 *
 * <p>The method is thread-safe.
 *
 * @param name Name of the attribute
 * @return The value of the attribute retrieved
 */
public static String read(final String name) {
    if (name == null) {
        throw new IllegalArgumentException("attribute can't be NULL");
    }
    if (name.isEmpty()) {
        throw new IllegalArgumentException("attribute can't be empty");
    }
    if (!Manifests.exists(name)) {
        throw new IllegalArgumentException(
            Logger.format(
                // @checkstyle LineLength (1 line)
                "Attribute '%s' not found in MANIFEST.MF file(s) among %d other attribute(s): %[list]s",
                name,
                Manifests.DEFAULT.get().size(),
                new TreeSet<String>(Manifests.DEFAULT.get().keySet())
            )
        );
    }
    return Manifests.DEFAULT.get().get(name);
}
 
开发者ID:jcabi,项目名称:jcabi-manifests,代码行数:33,代码来源:Manifests.java

示例8: apply

import com.jcabi.log.Logger; //导入方法依赖的package包/类
@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.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 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)
                )
            )
        );
    }
    return output;
}
 
开发者ID:yegor256,项目名称:jpeek,代码行数:35,代码来源:AsyncReports.java

示例9: body

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Push, collect logs, and wrap.
 * @return Logs
 * @throws IOException If fails
 */
private String body() throws IOException {
    final long start = System.currentTimeMillis();
    String log = this.log();
    if (!log.isEmpty()) {
        log = Logger.format(
            "%s\nDone. %tFT%<tRZ. %[ms]s spent.",
            log.trim(),
            new Date(),
            System.currentTimeMillis() - start
        );
    }
    return log;
}
 
开发者ID:yegor256,项目名称:wring,代码行数:19,代码来源:Exec.java

示例10: toString

import com.jcabi.log.Logger; //导入方法依赖的package包/类
@Override
public String toString() {
    return Logger.format(
        "[%d:%d] \"%s\", \"%s\", \"%s\", \"%s\"",
        this.iline,
        this.icolumn,
        this.isource,
        this.iexplanation,
        this.msg,
        this.imessage
    );
}
 
开发者ID:jcabi,项目名称:jcabi-w3c,代码行数:13,代码来源:Defect.java

示例11: waitFor

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Wait for this file to become available.
 * @param socket The file to wait for
 * @param port Port to wait for
 * @return The same socket, but ready for usage
 * @throws IOException If fails
 */
private File waitFor(final File socket, final int port) throws IOException {
    final long start = System.currentTimeMillis();
    long age = 0L;
    while (true) {
        if (socket.exists()) {
            Logger.info(
                this,
                "socket %s is available after %[ms]s of waiting",
                socket, age
            );
            break;
        }
        if (SocketHelper.isOpen(port)) {
            Logger.info(
                this,
                "port %s is available after %[ms]s of waiting",
                port, age
            );
            break;
        }
        try {
            TimeUnit.SECONDS.sleep(1L);
        } catch (final InterruptedException ex) {
            Thread.currentThread().interrupt();
            throw new IllegalStateException(ex);
        }
        age = System.currentTimeMillis() - start;
        if (age > TimeUnit.MINUTES.toMillis((long) Tv.FIVE)) {
            throw new IOException(
                Logger.format(
                    "socket %s is not available after %[ms]s of waiting",
                    socket, age
                )
            );
        }
    }
    return socket;
}
 
开发者ID:jcabi,项目名称:jcabi-mysql-maven-plugin,代码行数:46,代码来源:Instances.java

示例12: NodeNotFoundException

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Public ctor.
 * @param message Error message
 * @param node The XML with error
 * @param query The query in XPath
 */
NodeNotFoundException(final String message, final Node node,
    final CharSequence query) {
    super(
        Logger.format(
            "XPath '%s' not found in '%[text]s': %s",
            ListWrapper.NodeNotFoundException.escapeUnicode(query),
            ListWrapper.NodeNotFoundException.escapeUnicode(
                new XMLDocument(node).toString()
        ),
            message
    )
    );
}
 
开发者ID:jcabi,项目名称:jcabi-xml,代码行数:20,代码来源:ListWrapper.java

示例13: ofProviders

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Authenticate using providers.
 * @return Identity found or ANONYMOUS
 */
private Identity ofProviders() {
    Identity identity = Identity.ANONYMOUS;
    for (final Provider prov : this.providers) {
        try {
            identity = prov.identity();
        } catch (final IOException ex) {
            throw new IllegalStateException(ex);
        }
        if (!identity.equals(Identity.ANONYMOUS)) {
            if (prov.getClass()
                .isAnnotationPresent(Provider.Redirect.class)) {
                throw new AuthException(
                    Response
                        .status(HttpURLConnection.HTTP_SEE_OTHER)
                        .location(
                            this.resource.uriInfo().getRequestUriBuilder()
                                .replaceQuery("")
                                .build()
                        )
                        .cookie(this.cookie(identity))
                        .build(),
                    Logger.format(
                        "redirecting due to @Provider.Redirect at %[type]s",
                        prov
                    )
                );
            }
            break;
        }
    }
    return identity;
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:37,代码来源:AuthInset.java

示例14: getContext

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>JAXBContext is thread-safe, that's why we don't synchronize here.
 *
 * @see <a href="http://jaxb.java.net/guide/Performance_and_thread_safety.html">JAXBContext is thread-safe</a>
 */
@Override
@NotNull
public Marshaller getContext(@NotNull final Class<?> type) {
    Marshaller mrsh;
    try {
        mrsh = this.buildContext(type).createMarshaller();
        mrsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        final String header = Logger.format(
            "\n<?xml-stylesheet type='text/xsl' href='%s'?>",
            StringEscapeUtils.escapeXml11(this.stylesheet(type))
        );
        mrsh.setProperty("com.sun.xml.bind.xmlHeaders", header);
    } catch (final JAXBException ex) {
        throw new IllegalStateException(ex);
    }
    if (this.folder == null) {
        Logger.debug(
            this,
            "#getContext(%s): marshaller created (no XSD validator)",
            type.getName()
        );
    } else {
        this.addXsdValidatorToMarshaller(mrsh, type);
    }
    return mrsh;
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:34,代码来源:XslResolver.java

示例15: load

import com.jcabi.log.Logger; //导入方法依赖的package包/类
/**
 * Load template from URI.
 * @param uri The URI to load from
 * @return The text just loaded
 */
private static String load(final URI uri) {
    String txt;
    try {
        if (uri.isAbsolute()) {
            txt = IOUtils.toString(uri, Charsets.UTF_8);
        } else {
            final InputStream stream = StaticTemplate.class
                .getResourceAsStream(uri.toString());
            try {
                txt = IOUtils.toString(stream, Charsets.UTF_8);
            } finally {
                IOUtils.closeQuietly(stream);
            }
        }
    } catch (final IOException ex) {
        txt = Logger.format(
            "%s\nfailed to load '%s': %[exception]s",
            StaticTemplate.MARKER,
            uri,
            ex
        );
    }
    if (!txt.contains(StaticTemplate.MARKER)) {
        txt = Logger.format("%s\n%s", StaticTemplate.MARKER, txt);
    }
    return txt;
}
 
开发者ID:yegor256,项目名称:rexsl,代码行数:33,代码来源:StaticTemplate.java


注:本文中的com.jcabi.log.Logger.format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。