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


Java Logger类代码示例

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


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

示例1: getChatters

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Gets all user's present in the twitch chat of a channel.
 *
 * @param channelName Channel to fetch the information for.
 * @return All chatters in a channel, separated into groups like admins, moderators and viewers.
 */
public Chatter getChatters(String channelName) {
	// Endpoint
	String requestUrl = String.format("%s/group/user/%s/chatters", Endpoints.TMI.getURL(), channelName);
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// REST Request
	try {
		if (!restObjectCache.containsKey(requestUrl)) {
			Logger.trace(this, "Rest Request to [%s]", requestUrl);
			ChatterResult responseObject = restTemplate.getForObject(requestUrl, ChatterResult.class);
			restObjectCache.put(requestUrl, responseObject, ExpirationPolicy.CREATED, 60, TimeUnit.SECONDS);
		}

		return ((ChatterResult) restObjectCache.get(requestUrl)).getChatters();

	} catch (RestException restException) {
		Logger.error(this, "RestException: " + restException.getRestError().toString());
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	// OnError: Return empty result
	return new Chatter();
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:32,代码来源:TMIEndpoint.java

示例2: getFeatured

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Get Featured Streams
 * <p>
 * Gets a list of all featured live streams.
 * Requires Scope: none
 *
 * @param limit  Maximum number of most-recent objects to return. Default: 25. Maximum: 100.
 * @param offset Object offset for pagination of results. Default: 0.
 * @return The requested range/amount of featured streams.
 */
public List<StreamFeatured> getFeatured(Optional<Long> limit, Optional<Long> offset) {
	// Endpoint
	String requestUrl = String.format("%s/streams/featured", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// Parameters
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("limit", limit.orElse(25l).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("offset", offset.orElse(0l).toString()));

	// REST Request
	try {
		StreamFeaturedList responseObject = restTemplate.getForObject(requestUrl, StreamFeaturedList.class);

		return responseObject.getFeatured();
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return new ArrayList<StreamFeatured>();
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:32,代码来源:StreamEndpoint.java

示例3: getRecommendations

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Get recommended streams for User (Unofficial)
 * Gets a list of recommended streams for a user.
 * Requires Scope: none
 *
 * @param credential OAuthCredential of the user, you want to request recommendations for.
 * @return StreamList of random Streams.
 */
@Unofficial
public List<Recommendation> getRecommendations(OAuthCredential credential) {
	// Endpoint
	String requestUrl = String.format("%s/streams/recommended", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// Parameters
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("oauth_token", credential.getToken()));

	// REST Request
	try {
		Logger.trace(this, "Rest Request to [%s]", requestUrl);
		RecommendationList responseObject = restTemplate.getForObject(requestUrl, RecommendationList.class);

		return responseObject.getRecommendedStreams();
	} catch (RestException restException) {
		Logger.error(this, "RestException: " + restException.getRestError().toString());
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return null;
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:33,代码来源:StreamEndpoint.java

示例4: getGames

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Endpoint: Search Games
 * Searches for games based on a specified query parameter. A game is returned if the query parameter is matched entirely or partially, in the game name.
 * Requires Scope: none
 *
 * @param query search query
 * @param live Whether only games that are live should be returned. This argument is optional.
 * @return A list of games matching the query.
 */
public List<Game> getGames(String query, Optional<Boolean> live) {
	// Endpoint
	String requestUrl = String.format("%s/search/games", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// Parameters
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("query", query));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("live", live.orElse(false).toString()));

	// REST Request
	try {
		GameList responseObject = restTemplate.getForObject(requestUrl, GameList.class);

		return responseObject.getGames();
	} catch (RestException restException) {
		Logger.error(this, "RestException: " + restException.getRestError().toString());
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return null;
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:33,代码来源:SearchEndpoint.java

示例5: processSubevents

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Processes subevents of the key.
 * @param key That has new events.
 * @param dir For the key.
 * @throws IOException If a subdirectory cannot be registered.
 */
private void processSubevents(final WatchKey key, final Path dir)
    throws IOException {
    for (final WatchEvent event : key.pollEvents()) {
        final WatchEvent.Kind kind = event.kind();
        final Path name = (Path) event.context();
        final Path child = dir.resolve(name);
        Logger.debug(
            this,
            "%s: %s%n", event.kind().name(), child
        );
        if (kind == ENTRY_CREATE) {
            try {
                if (Files.isDirectory(child)) {
                    this.processSubevents(child);
                }
            } catch (final IOException ex) {
                throw new IOException(
                    "Failed to register subdirectories.",
                    ex
                );
            }
        }
    }
}
 
开发者ID:driver733,项目名称:VKMusicUploader,代码行数:31,代码来源:WatchDirs.java

示例6: firstValid

import com.jcabi.log.Logger; //导入依赖的package包/类
@Override
@Cacheable(forever = true)
public byte[] firstValid() throws IOException {
    byte[] result = new byte[0];
    for (final ByteArray array : this.arrays) {
        try {
            result = array.toByteArray();
            break;
        } catch (final IOException ignored) {
            Logger.debug(this, ignored.getMessage());
        }
    }
    if (result.length == 0) {
        throw new IOException("No valid ByteArray found.");
    }
    return result;
}
 
开发者ID:driver733,项目名称:VKMusicUploader,代码行数:18,代码来源:FallbackByteArray.java

示例7: scheduleTasks

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * schedule tasks for pinging WebSocket server.
 */
private void scheduleTasks() {
	timer.scheduleAtFixedRate(new TimerTask() {
		@Override
		public void run() {
			// Prepare JSON Ping Message
			try {
				ObjectMapper mapper = new ObjectMapper();
				ObjectNode objectNode = mapper.createObjectNode();
				objectNode.put("type", "PING");

				webSocket.sendText(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(objectNode));

				Logger.debug(this, "Send Ping to Twitch PubSub. (Keep-Connection-Alive)");
			} catch (Exception ex) {
				Logger.error(this, "Failed to Ping Twitch PubSub. (%s)", ex.getMessage());
				reconnect();
			}

		}
	}, 7000, 282000);
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:25,代码来源:TwitchPubSub.java

示例8: execType

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Executing data to Twitch PubSub
 * @param type data type ("LISTEN" or "UNLISTEN")
 * @param topics string {@link List} of topics
 */
private void execType(String type, List<String> topics) {
	// Check Connection
	if (!getConnectionState().equals(TMIConnectionState.CONNECTED)) {
		return;
	}

	ObjectMapper mapper = new ObjectMapper();
	ObjectNode node = mapper.createObjectNode();
	node.put("type", type.toUpperCase())
			.put("nonce", identifyNonce);
	ArrayNode topicList = mapper.createArrayNode();
	topics.forEach(topicList::add);
	node.putObject("data")
			.put("auth_token", "") // TODO: OAuth if exist.
			.putArray("topics").addAll(topicList);
	Logger.debug(this, "Sending to PubSub - type: %s, topics: [ %s ]", type.toUpperCase(), String.join(", ", topics));
	webSocket.sendText(node.toString());
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:24,代码来源:TwitchPubSub.java

示例9: sendMessage

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Sending message to the joined channel
 * @param channel channel name
 * @param message message
 */
public void sendMessage(String channel, String message) {
	Logger.debug(this, "Sending message to channel [%s] with content [%s].!", channel, message);
	new Thread(() -> {
		// Consume 1 Token (wait's in case the limit has been exceeded)
		if (isModerator(channel)) {
			// Only for channels if bot is moderator
			modMessageBucket.get(channel).consume(1);
		} else {
			messageBucket.consume(1);
		}

		// Send Message
		sendCommand("privmsg", "#" + channel, ":" + message);

		// Logging
		Logger.debug(this, "Message send to Channel [%s] with content [%s].", channel, message);
	}).start();
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:24,代码来源:TwitchChat.java

示例10: getTeams

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Endpoint: Get All Teams
 * Gets all active teams.
 * Requires Scope: none
 *
 * @param limit  Maximum number of most-recent objects to return. Default: 25. Maximum: 100.
 * @param offset Object offset for pagination. Default is 0.
 * @return todo
 */
public List<Team> getTeams(Optional<Long> limit, Optional<Long> offset) {
	// Endpoint
	String requestUrl = String.format("%s/teams", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// Parameters
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("limit", limit.orElse(25l).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("offset", offset.orElse(0l).toString()));

	// REST Request
	try {
		Logger.trace(this, "Rest Request to [%s]", requestUrl);
		TeamList responseObject = restTemplate.getForObject(requestUrl, TeamList.class);

		return responseObject.getTeams();
	} catch (RestException restException) {
		Logger.error(this, "RestException: " + restException.getRestError().toString());
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return null;
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:34,代码来源:TeamEndpoint.java

示例11: getTopGames

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Endpoint: Get Top Games
 * Get games by number of current viewers on Twitch.
 * Requires Scope: none
 *
 * @return todo
 */
public List<TopGame> getTopGames() {
	// Endpoint
	String requestUrl = String.format("%s/games/top", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// REST Request
	try {
		Logger.trace(this, "Rest Request to [%s]", requestUrl);
		TopGameList responseObject = restTemplate.getForObject(requestUrl, TopGameList.class);

		return responseObject.getTop();
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return null;
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:26,代码来源:GameEndpoint.java

示例12: getTeams

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Endpoint: Get Channel Teams
 * Gets a list of teams to which a specified channel belongs.
 * Requires Scope: none
 *
 * @return todo
 */
public List<Team> getTeams() {
	// Endpoint
	String requestUrl = String.format("%s/channels/%s/teams", Endpoints.API.getURL(), getChannelId());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// REST Request
	try {
		TeamList responseObject = restTemplate.getForObject(requestUrl, TeamList.class);

		return responseObject.getTeams();
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
		return null;
	}
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:24,代码来源:ChannelEndpoint.java

示例13: getVideos

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Endpoint: Get Channel Videos
 * Gets a list of videos from a specified channel.
 * Requires Scope: none
 *
 * @param limit          Maximum number of most-recent objects to return. Default: 25. Maximum: 100.
 * @param offset         Object offset for pagination of results. Default: 0.
 * @param sort           Sorting order of the returned objects. Valid values: views, time. Default: time (most recent first).
 * @param language       Constrains the language of the videos that are returned; for example, *en,es.* Default: all languages.
 * @param broadcast_type Constrains the type of videos returned. Valid values: (any combination of) archive, highlight, upload, Default: highlight.
 * @return todo
 */
public List<Video> getVideos(Optional<Long> limit, Optional<Long> offset, Optional<String> sort, Optional<String> language, Optional<String> broadcast_type) {
	// Endpoint
	String requestUrl = String.format("%s/channels/%s/videos", Endpoints.API.getURL(), getChannelId());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// Parameters
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("limit", limit.orElse(25l).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("offset", offset.orElse(0l).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("sort", sort.orElse("time").toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("language", language.orElse(null).toString()));
	restTemplate.getInterceptors().add(new QueryRequestInterceptor("broadcast_type", broadcast_type.orElse("highlight").toString()));

	// REST Request
	try {
		VideoList responseObject = restTemplate.getForObject(requestUrl, VideoList.class);

		return responseObject.getVideos();
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
		return null;
	}
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:36,代码来源:ChannelEndpoint.java

示例14: getToken

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Endpoint: Get OAuth Token Information
 * Gets information about the provided oAuthToken
 * Requires Scope: none
 *
 * @param credential The credential the information should be fetched for.
 * @return Information about the user, that issued the token - also provides info about scopes/valid/etc.
 * @see Token
 */
public Token getToken(OAuthCredential credential) {
	// Endpoint
	String requestUrl = String.format("%s", Endpoints.API.getURL());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getPrivilegedRestTemplate(credential);

	// REST Request
	try {
		TokenResponse responseObject = restTemplate.getForObject(requestUrl, TokenResponse.class);

		return responseObject.getToken();
	} catch (RestException restException) {
		Logger.error(this, "RestException: " + restException.getRestError().toString());
	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	// Default Response: Invalid Token
	return new Token();
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:30,代码来源:KrakenEndpoint.java

示例15: getByChannel

import com.jcabi.log.Logger; //导入依赖的package包/类
/**
 * Get Stream by Channel
 * <p>
 * Gets stream information (the stream object) for a specified channel.
 * Requires Scope: none
 *
 * @param channel Get stream object of Channel Entity
 * @return Optional of type Stream is only Present if Stream is Online, returns Optional.empty for Offline streams
 */
public Optional<Stream> getByChannel(Channel channel) {
	// Endpoint
	String requestUrl = String.format("%s/streams/%s", Endpoints.API.getURL(), channel.getId());
	RestTemplate restTemplate = getTwitchClient().getRestClient().getRestTemplate();

	// REST Request
	try {
		StreamSingle responseObject = restTemplate.getForObject(requestUrl, StreamSingle.class);

		// Stream Offline
		if (responseObject.getStream() == null) {
			// Stream Offline
			return Optional.empty();
		} else {
			// Stream Online
			return Optional.ofNullable(responseObject.getStream());
		}

	} catch (Exception ex) {
		Logger.error(this, "Request failed: " + ex.getMessage());
		Logger.trace(this, ExceptionUtils.getStackTrace(ex));
	}

	return null;
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:35,代码来源:StreamEndpoint.java


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