Search in sources :

Example 1 with Logger

use of org.craftercms.studio.api.v1.log.Logger in project studio by craftercms.

the class L4jLogProvider method getLogger.

/**
 * return a logger implementation
 * @param targetClass ther target class for the logger
 */
public Logger getLogger(Class targetClass) {
    Logger retLogger = null;
    org.slf4j.Logger l4jLogger = org.slf4j.LoggerFactory.getLogger(targetClass);
    retLogger = new LoggerImpl(l4jLogger);
    return retLogger;
}
Also used : Logger(org.craftercms.studio.api.v1.log.Logger)

Example 2 with Logger

use of org.craftercms.studio.api.v1.log.Logger in project studio by craftercms.

the class DebugUtils method addDebugStack.

public static void addDebugStack(Logger logger) {
    if (logger.getLevel().equals(Logger.LEVEL_DEBUG)) {
        Thread thread = Thread.currentThread();
        String threadName = thread.getName();
        logger.debug("Thread: " + threadName);
        StackTraceElement[] stackTraceElements = thread.getStackTrace();
        StringBuilder sbStack = new StringBuilder();
        int stackSize = (20 < stackTraceElements.length - 2) ? 20 : stackTraceElements.length;
        for (int i = 2; i < stackSize + 2; i++) {
            sbStack.append("\n\t").append(stackTraceElements[i].toString());
        }
        RequestContext context = RequestContext.getCurrent();
        CronJobContext cronJobContext = CronJobContext.getCurrent();
        if (context != null) {
            HttpServletRequest request = context.getRequest();
            String url = request.getRequestURI() + "?" + request.getQueryString();
            logger.debug("Http request: " + url);
        } else if (cronJobContext != null) {
            logger.debug("Cron Job");
        }
        logger.debug("Stack trace (depth 20): " + sbStack.toString());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CronJobContext(org.craftercms.studio.api.v1.job.CronJobContext) RequestContext(org.craftercms.commons.http.RequestContext)

Example 3 with Logger

use of org.craftercms.studio.api.v1.log.Logger in project studio by craftercms.

the class ContentServiceImpl method getContentItemTree.

@Override
@ValidateParams
public ContentItemTO getContentItemTree(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateIntegerParam(name = "depth") int depth) {
    logger.debug("Getting content item  tree for '{}':'{}' depth '{}'", site, path, depth);
    DebugUtils.addDebugStack(logger);
    long startTime = System.currentTimeMillis();
    boolean isPages = (path.contains(FILE_SEPARATOR + "site" + FILE_SEPARATOR + "website"));
    ContentItemTO root = null;
    if (isPages && contentExists(site, path + FILE_SEPARATOR + DmConstants.INDEX_FILE)) {
        if (depth > 1) {
            root = getContentItem(site, path + FILE_SEPARATOR + DmConstants.INDEX_FILE, depth);
        } else {
            root = getContentItem(site, path + FILE_SEPARATOR + DmConstants.INDEX_FILE);
        }
    } else {
        if (depth > 1) {
            root = getContentItem(site, path, depth);
        } else {
            root = getContentItem(site, path);
        }
    }
    long executionTime = System.currentTimeMillis() - startTime;
    logger.debug("Content item tree ['{}':'{}' depth '{}'] retrieved in '{}' milli-seconds", site, path, depth, executionTime);
    return root;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 4 with Logger

use of org.craftercms.studio.api.v1.log.Logger in project studio by craftercms.

the class ContentServiceImpl method getContentItem.

@Override
@ValidateParams
public ContentItemTO getContentItem(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateIntegerParam(name = "depth") int depth) {
    ContentItemTO item = null;
    logger.debug("Getting content item for site '{}' path '{}' depth '{}'", site, path, depth);
    DebugUtils.addDebugStack(logger);
    long startTime = System.currentTimeMillis();
    try {
        if (contentExists(site, path)) {
            // get item from cache
            item = loadContentItem(site, path);
            if (depth != 0) {
                item = populateItemChildren(item, depth);
            }
            // POPULATE LOCK STATUS
            populateMetadata(site, item);
            // POPULATE WORKFLOW STATUS
            if (!item.isFolder() || item.isContainer()) {
                populateWorkflowProperties(site, item);
            } else {
                item.setNew(!objectStateService.isFolderLive(site, item.getUri()));
                item.isNew = item.isNew();
            }
        } else {
            item = createDummyDmContentItemForDeletedNode(site, path);
        }
    } catch (Exception err) {
        logger.debug("error constructing item for object at site '{}' path '{}'", err, site, path);
    }
    long executionTime = System.currentTimeMillis() - startTime;
    logger.debug("Content item from site '{}' path '{}' retrieved in '{}' milli-seconds", site, path, executionTime);
    return item;
}
Also used : ContentItemTO(org.craftercms.studio.api.v1.to.ContentItemTO) ServiceLayerException(org.craftercms.studio.api.v1.exception.ServiceLayerException) IOException(java.io.IOException) AuthenticationException(org.craftercms.studio.api.v1.exception.security.AuthenticationException) InvalidRemoteUrlException(org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException) SAXException(org.xml.sax.SAXException) ContentNotFoundException(org.craftercms.studio.api.v1.exception.ContentNotFoundException) DocumentException(org.dom4j.DocumentException) EntitlementException(org.craftercms.commons.entitlements.exception.EntitlementException) SiteNotFoundException(org.craftercms.studio.api.v1.exception.SiteNotFoundException) CryptoException(org.craftercms.commons.crypto.CryptoException) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Aggregations

ValidateParams (org.craftercms.commons.validation.annotations.param.ValidateParams)2 ContentItemTO (org.craftercms.studio.api.v1.to.ContentItemTO)2 IOException (java.io.IOException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 CryptoException (org.craftercms.commons.crypto.CryptoException)1 EntitlementException (org.craftercms.commons.entitlements.exception.EntitlementException)1 RequestContext (org.craftercms.commons.http.RequestContext)1 ContentNotFoundException (org.craftercms.studio.api.v1.exception.ContentNotFoundException)1 ServiceLayerException (org.craftercms.studio.api.v1.exception.ServiceLayerException)1 SiteNotFoundException (org.craftercms.studio.api.v1.exception.SiteNotFoundException)1 InvalidRemoteUrlException (org.craftercms.studio.api.v1.exception.repository.InvalidRemoteUrlException)1 AuthenticationException (org.craftercms.studio.api.v1.exception.security.AuthenticationException)1 CronJobContext (org.craftercms.studio.api.v1.job.CronJobContext)1 Logger (org.craftercms.studio.api.v1.log.Logger)1 DocumentException (org.dom4j.DocumentException)1 SAXException (org.xml.sax.SAXException)1